A 'Python like' language

Sean Ross sross at connectmail.carleton.ca
Mon Mar 29 12:30:09 CEST 2004


> > * A bit of syntactic sugar for defining prototype objects
> >    wouldn't go amiss. Having to say
> >
> >      Thing = Base()
> >      with Thing:
> >         ...
> >
> >    every time I want to define a class (oops, sorry, prototype)
> >    would drive me batty. I'd much rather write something like
> >
> >      object Thing(Base):
> >        ...
> >


In Io (www.iolanguage.com):

Thing := Object clone do(
        # evaluates in context of Thing, i.e., Thing is the locals object of
do()
        slot := "new slot for Thing"
)

Thing slot print   # <-  "new slot for Thing"

There's some fancy footwork going on that I won't go into at the moment -
its 5am - but suffice to say that namespaces are handled by objects and
message forwarding and one of the tricks of this process is that a method
has 'self', 'proto', 'sender', and 'locals' slots. In the case of do(),
locals == self == sender (I think).  Anyway, for Prothon, perhaps you'll
want to reserve "do" for blocks, so we'll try "where":

Thing = Object.clone() where:
        attr = "new attribute for Thing"
print Thing.attr   # <- "new attribute for Thing"


I'm not sure how that'd be made to work though - in Io, do() is just another
method of Object (there are no keywords).

The namespaces are handled by objects idea seems to play out nicely - for
one thing, there's no reason to distinguish globals via capitalization.
Also, having two forms of assignment (one for creation(binding), and one for
update(re-binding)) eliminates alot of the need for the '.' prefix stuff in
Prothon - use "self.attr" once on creation to let the namespace know what
you're doing and from then on , as long as you don't shadow it by creating a
local of the same name, you can just say "attr". If you're only doing
updates on "attr", in a given namespace, you never need to use "self.attr" -
the lookup mechanism will just resolve it for you.


Anyway, that's enough from me, I have a lab exam to study for.

Sean





More information about the Python-list mailing list