[squeak-dev] Re: About classVariables
nicolas cellier
ncellier at ifrance.com
Mon Oct 13 19:55:23 UTC 2008
Eliot Miranda a écrit :
>
>
> On Mon, Oct 13, 2008 at 2:02 AM, Martin Beck
> <martin.beck at hpi.uni-potsdam.de <mailto:martin.beck at hpi.uni-potsdam.de>>
> wrote:
>
> Craig Latta wrote:
> >
> > Hi Stef--
> >
> >> To my stupefaction I discovered that the classVariables of a
> class are
> >> not the same as the ones of its metaclass.
> >>
> >> TheRoot classVarNames ~= TheRoot class classVarNames
> >>
> >> Does any body have some ideas why this is like that? For me this
> is a
> >> conceptual bug.
> >
> > Actually, metaclasses don't really have class variables at all.
> > Class variables are defined by Class, which is a sibling of
> Metaclass,
> > not a superclass. There's a method in Behavior which just answers
> a new
> > empty Set for classVarNames; this is what you're invoking when you
> > evaluate [TheRoot class classVarNames].
> >
> However,
>
> TheRoot classPool = TheRoot class classPool
>
> evaluates to true...
>
> Regards,
> Martin
>
>
> One fix is to add the following method:
> ------------8<-----------
> !Metaclass methodsFor: 'class variables' stamp: 'eem 10/13/2008 12:37'!
> classVarNames
> "Answer a Set of the names of the class variables defined in the
> receiver's instance."
>
> ^thisClass classVarNames! !
> ------------8<-----------
> c.f. Metaclass>>classPool.
>
> But a better fix is to move Class>>classVarNames to ClassDescription:
> ------------8<-----------
> 'From Croquet1.0beta of 11 April 2006 [latest update: #1] on 13 October
> 2008 at 12:41:36 pm'!
>
> !ClassDescription methodsFor: 'class variables' stamp: 'eem 10/13/2008
> 12:41'!
> classVarNames
> "Answer a Set of the names of the class variables defined in the receiver."
>
> ^self classPool keys! !
>
> Class removeSelector: #classVarNames!
> ------------8<-----------
>
> Whoever said that the class variables of a metaclass should be those of
> Metaclass is very wrong. Code compiled in the context of a metaclass
> includes the class variables of the non-metaclass (metaclass's
> instance), otherwise one couldn't access class variables in class-side
> methods.
>
>
> ------------------------------------------------------------------------
>
>
It is funny with Object because:
(Object class allSuperclasses includes: Object).
So the Object classPool keys will be accessible twice (It does not seem
to hurt).
Nicolas
More information about the Squeak-dev
mailing list
|