Re: Re:class proposal 2
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Lucius, Michael wrote: >> ... It's prototype list will point to other classes >> giving the normal class inheritance heirarchy. > > I assume you mean the class object will have the same protoypes as the > instance object. No the instance object would have only one prototype, which is the class object. Then the class object would have the references to the other classes. > This means the class object will be an extension of the same > prototypes as the instance object and so the class instance will not > have access to the instance's methods/data. Or is 'self' going to be > set to be the instance? Self will always refer to the actual instance object. >> ... Access to class methods inside a >> normal method or inside a class definition would be through the >> normal "Klass.class.method()" or through new syntax sugar that makes >> use of the class keyword as a prefix "class.method()". > > How about the other way around? Is there a special way for class > methods to access 'normal' methods that are defined in the instance > or is this not allowed? Or must class methods access other class > methods in a special way? Now you are getting into an area that is screwed up in my proposal. In Python you can say Klass.method() to access an instance method but that wouldn't work in my proposal, even though instance methods are attributes of Klass. My weird lookup rule would screw that up. >> --- When an attribute is first being looked up in an immediate >> object, not an ancestor, and a attribute named "class" exists in the >> immediate object, that class attribute object is used in the >> object's place for the >> lookup. --- >> > > So under certain circumstances a special 'class scope' is inserted at > the head > (or near the head) of the scope chain? > >> class Klass(Parent1, Parent2): >> """Class document string""" >> >> class: > > Can 'class:' be used in an 'object' block or only in a 'class' block? I would think only in a class block. > Here is my proposal: > > When defining an Object Klass: > add a function class_() that defines an inner class. > This inner class has Klass as its prototype and defines call_(), > str_() > and whatever else the class needs and returns that object. This > inserts the 'class scope' as your proposal does by using existing > functionality and does not require anything special be done in the > language. > > Then you have: > KlassFactory = Klass.class_() # returns Klass object that acts like > a class > newKlass = KlassFactory() # uses call_() from 'class scope' > KlassFactory.str_() # uses str_() fron 'class scope' Your solution solves the dual namespace problem in a much cleaner way than mine. It doesn't solve the problem of how to allow call_ and str_ to be used at the same time for both classes and instances though. Mine doesn't either since I found out my solution is broken. Without such a solution both of our proposals are just programming techniques, not language features. > When defining a class Klass: > add a function object_() which defines the behavior as an object > instance. So object_() is like the above class_() but behaves like a > regular instance. This means that the default behaviour is class > behaviour and Klass.object_() returns an object that has put instance > methods/data at > the head of the scope chain. > > This introduces a difference between object and class. > object: acts like an instance by default, but can be used as a class > if desired. > class: acts like a class by default, but can easily used as an > instance. > > I think this leverages the ability of protoypes to delegate > automatically This I don't understand. It seems to me you are just interchanging the names. The behaviour of your Class inside an object is identical to your object inside a Class.