RE: Re[2]: Re: Knowing about Inheritance

"Mark Hahn" <[email protected]> Fri, 30 Jul 2004 22:49:49 -0700
Newsgroups gmane.comp.lang.prothon.user
Message-ID <000201c476c2$31c6c660$0b01a8c0@mark>
Lenard Lindstrom wrote:

>> Lenard 
>> made a claim at one point that Prothon couldn't do a metaclass and 
>> when I called him on it he backed off and said he didn't know for 
>> sure.  I added an item to the Wiki for the 1.0 release to 
>> find out and 
>> make sure it can but it ended up on the future-release list.
>
>It has to do with the way Python's class statement works. 
>Unlike the object statement the body of the class statement is 
>evaluated before the actual class object is created. The local 
>scope of the class statement is passed to the class 
>constructor function - metaclass - as a dictionary. So a user 
>provided class creation function can scan the dictionary, 
>which contains class attributes, and decide what to do with 
>them. It also gets the inheritance list so it can manipulate 
>that as well. So a user provided metaclass can add additional 
>attributes and parent classes behind the scene.

A callback at the end of an object block could also add additional
attributes and parent classes.

>In Python metaclasses are inherited. That is how new-style 
>classes work. They all inherit object's metaclass. So entirely 
>new class systems can be created simply by inheriting from a 
>common root class. I do not know if simular lineages are 
>possible with prototypes. It may involve overriding call_.
>
>All I can say is that metaclassing requires a language where 
>an object's type, including a class object, is defined by a 
>class. In a prototype based language all objects have the same 
>implicit type and it is hardcoded into the interpreter. 
>Whether or not this limits prototype versatility I do not 
>know. It may be prototypes provide equally useful alternatives 
>to metaclasses. I have not had enough experience with either 
>prototypes or useful metaclass examples to make a judgment.

I think this is such a complex subject that it may take a while to really
tell whether something as simple as an object block callback can replace
something as complex as metaclasses.  If it could that would be a great
simplification.

I'm an optimist of course, but my simple thought experiments so far look
good.  My next step is to take the example metaclasses that Serge gave me
and try to rewrite them with the object statement callback.

One problem that I can see is that the objects have to be created in order
from the root of the tree outwards.  If you were to create the leaf object
first and then add the prototype to it by changing it's prototype, the
callback wouldn't work (or I should say it would be quite hard for me to
make it work right).