Re: Re: Re: What problem are we trying to solve?
Greg Ewing <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Mark Hahn <[email protected]>: > Another way of saying it is that each layer of the inheritance hierarchy > needs two objects if you want dual namespaces to solve the "call_/str_" > problem. Here's another dual-namespace idea that's the opposite way around from yours. Instead of having a sub-object in the instance for things that apply only to the instance, have one in the prototype for things that *don't* apply to the prototype. This would be more efficient, since it means only one extra object per prototype instead of per instance. The extra object could be called 'methods_' since it would be used to hold functions that should apply to the instances but not to the prototype. The lookup rules would be: (1) Look in the object. (2) If the object has a single prototype with a methods_ attribute, continue looking there and in its prototypes. (3) Otherwise, continue looking in the object's prototypes as usual. For this to have the desired effect, it would be necessary for inheritance of methods to be specified slightly differently. Here's an example: object MyProto: object methods_: def str_(): return "an instance of MyProto" object MyOtherProto: object methods_(MyProto.methods_): def call_(): # do something special print str(MyProto) # These both invoke the str_ inherited from Object print str(MyOtherProto) myInst = MyProto() # invokes the default call_ inherited from Object print str(myInst) # invokes MyProto.methods_.str_ myOtherInst = MyOtherProto() # default call_ again print str(myOtherInst) # MyProto.methods_.str_ again myOtherInst() # MyOtherProto.methods_.call_ One other change is that a directed super call would have to be written SomeProto.methods_.someMethod{self}(args) Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | [email protected] +--------------------------------------+