[PY!] Playing with Py
Hope this is not considered off-topic, but Dave's Py turns out to have some
very interesting and potentially userful features. Here's one:
----------
-- fruit.pi --
----------
variety = ""
color = ""
price = 6.99
def info()
printf(1,"Fruit is %s, color is %s, and price is %4.2f\n",
variety,color,price)
end def
Save the above as "fruit.pi", then run Py in interactive mode:
+==========================================+
| Py version 2.2a |
| Built: October 20, 2000 |
|==========================================|
| Py (c) David Cuny |
| Euphoria (c) Rapid Development Software |
| Dictionary code (c) Jiri Babor |
+==========================================+
type 'bye' to exit
Py > import "fruit.pi" as Apple
Py > import "fruit.pi" as Peach
Py > import "fruit.pi" as Cherry
Py > Apple.variety = "Mackintosh"
Py > Cherry.variety = "Moreton"
Py > Apple.color = "Red"
Py > Cherry.color = Apple.color
Py > Apple.price = 3.99
Py > Apple.info()
Fruit is Mackintosh, color is Red, and price is 3.99
Py > Cherry.info()
Fruit is Moreton, color is Red, and price is 6.99
Py > Peach.info()
Fruit is , color is , and price is 6.99
Py >bye
It turns out that Py can import the same file numerous times, and each time
creates a completely separate and independent set of variables and functions
within the namespace given. Here are my long-awaited structures, plus quite
likely some interesting OOP-like characteristics.
Hmmmm.
Irv
|
Not Categorized, Please Help
|
|