1. [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

new topic     » topic index » view message » categorize

2. Re: [PY!] Playing with Py

Irv wrote:

> OOP

I had the same sort of thought, and figured that when Robert implements
namespaces in Euphoria, we'll get OOP features as well. The problem is that
variables are statically bound, so you can't generalize it to:

   def show_info( fruit )
      ? fruit.type -- undefined
   end def

or in Euphoria (assuming namespaces)

   procedure show_info( sequence fruit )
      ? fruit.type -- undefined
   end procedure

Sorry. I may consider adding dynamic binding later (and allowing OOP), but
for now, I'm sticking rather close to the Euphoria model.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu