New meaning of super ^
"Mark Hahn" <[email protected]> Wed, 31 Mar 2004 19:16:02 -0800
| Newsgroups | gmane.comp.lang.prothon.devel |
|---|---|
| Message-ID | <031d01c41797$aaa16160$d701a8c0@MarkVaio> |
Greg Ewing found out that super was broken and I just fixed it today (build
244). His test case was:
Mammal = Object()
with Mammal:
def .describe():
print "I am a mammal."
.make_noise()
def .make_noise():
print "I make some kind of noise."
Cat = Mammal()
with Cat:
def .describe():
print "I am a cat."
^describe() # <-- super call
def .make_noise():
print "I go meow."
c = Cat()
c.describe()
It prints out:
I am a cat.
I am a mammal.
I go meow.
I had to make a change to the meaning of the super prefix to make this work.
I want everyone to try to shoot holes in my new meaning and see if it will
have problems in other usage cases.
When the ^describe() call is made, it calls the "second" describe() function
that it finds in the list of prototypes. The first is found in the Cat
prototype and the second is found in the Mammal prototype.
My old definition was that it looked for .describe in all "ancestors" of
"self" which was "c". This clearly was wrong since Cat was an "ancestor" of
"c". Any definition of super based on ancestor count would be useless
because you can do ...
c = Cat()
d = c()
e = c()
with e:
^describe()
... and expect to get the describe in Mammal.
By the way, when I was testing, I found myself wanting to do e^describe()
instead of using the "with" clause above. Does anyone think that ^ should
be allowed to be used where period is used in a "path"?