> >>>>> "GvR" == Guido van Rossum <guido@digicool.com> writes: > > GvR> Let x be an object, C its class, and M C's class. So, > > | x.__class__ is C > | C.__class__ is M > > GvR> Then x's methods are described in C.__dict__, and C's methods > GvR> are described in M.__dict__. > > GvR> The problem is that if you write C.spam, there could be two > GvR> spams: one in C.__dict__, one in M.__dict__. Which one to > GvR> use? > [Barry wrote] > If you use naming to generally distinguish, and have a lookup chain > that first found it in C.__dict__ and then looked in M.__dict__, you > could control what happens when the name is in both dicts by using a > more explicit lookup, e.g. C.__dict__['meth'] > vs. C.__class__.__dict__['meth'] > Couldn't be C.__class__.meth be used? > But maybe that's too ugly. > > GvR> How does Smalltalk resolve this? I'm walking on thin ice here (maybe I should better try it out), but IIRC Smalltalk requires to explicit: self class method; or self method; > Another question: presumably when I write > > class Foo: pass > > Foo is implicitly given the built-in metaclass M, but say I wanted to > define a class Foo with a different metaclass, how would I spell this? > I think at one point I suggested a semi-ugly syntactic hack, where > `class' was actually a namespace and you could add new metaclasses to > it. So you could write something like > > class.WeirdClass Foo: pass > > and now Foo's metaclass would be WeirdClass. Thin ice again I'm on here (even more), but I have the impression that creating a class Point in Smalltalk _automatically_ creates two classes: Point and PointClass. The latter is normally hidden (but contains the class methods of Point as instance methods). Thomas
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4