[Python-Dev] prototypes (was: Type/class) (original) (raw)

Steven D. Majewski sdm7g@Virginia.EDU
Sat, 12 May 2001 11:07:06 -0400 (EDT)


[Guido]

Do prototype-based language have the equivalence of multiple inheritance?

Yeah ... What Tim said...

Also: There are two basic implementation models:

Delegation [a.k.a. "Lifetime sharing", cloning] sort of like python -- if you don't know how to handle it "ask" a parent object. ( "ask" in quotes, because I've recently been in a long argument about whether objective-C & smalltalk can really be said to "send messages" , or if it's "just" dynamic lookup and function application! )

Extension [a.k.a. "Birth sharing", copying, concatenation ] more like how I imaging C++ vtables are built -- the python equivalent would be like merging all of the class dict's together with name-clase priority going to the nearest relative.

( "Life Sharing" vs. "Birth Sharing" -- is a change in the base class after object creation inherited by the object? )

I think most Multiple-Inheritance languages use delegation, but no reason it won't work in extension. The diff is that in extension, everything has to get resolved at object creation. Extension could be made more flexible if on creation, you could not only add new methods, but rearrange and control the extension process ( sort of like "from xxx import yyy; from aaa import bbb" ). I would think one could use delegation by default, but provide an extension mechanism as an optimization, but I don't know if there's any system that does this.

If it follows the paradigm, a prototype system doesn't have an 'isa' or 'class' slot -- only a (linked) list of parent objects. But if you were simulating class orientation, one would add an 'isa' slot for the immediate prototype, and probably enforce some restrictions on the prototype objects that were playing the role of class objects.

"If it follow the paradigm" -- as in OO in general, there are several flavors and implementations and some are may be hybrid systems. Self is the language most widely known as a prototype based language: some others: Newtonscript (from apple's late lamented Newton palmtop), Kevo (a forth based o-o language), Cardelli's Obliqu (This didn't stick in my mind from when I read the papers back in the "safe python" development days, but it's listed in my book.) as well as XlispStat's object system. (which isn't listed in that book but there is an ObjectLisp -- I don't know if they were at all related. ) -- and Tim said JavaScript. The Amulet and Garnet GUI systems are prototype based -- Garnet written in Lisp and Amulet in C++.

For NewtonScript, Kevo, and maybe JavaScript, I suspect the simplicity of the system was a motivation.

("the book" I'm reading is "Prototype-Based Programming -- Concepts, Languages and Applications" ed. James Noble, Antero Taivalsaari, Ivan Moore, pub. Springer. A collection of papers, some of which are available on the Web -- I know the Self papers, one description of NewtonScript, and one or two articles on Kevo are online, as well as Cardelli's Obliq paper. )

-- "Steve" Majewski