[squeak-dev] Re: About classVariables

Craig Latta craig at netjam.org
Fri Oct 17 20:53:52 UTC 2008


Hi Eliot--

 > When compiling code in Foo class, as opposed to Foo, the compiler
 > asks Foo class to lookup variables, not Foo.

      I didn't say it would (although when looking for Foo's class 
variables, (Foo class) will delegate to Foo).

 > Hence if the code refers to a class inst var of Foo it will be in
 > scope because this class inst var will be one of Foo class's inst
 > vars.

      No, it's in scope because it's a class inst var of *Foo*, like you 
said in the first part of your sentence. :) In particular, the class 
instance variable will have been put in the encoder's scopeTable by an 
earlier invocation of Encoder>>init:context:notifying:.

 > Similarly, when the compiler asks Foo class to bind a variable that is
 > actually a class variable of Foo, it is up to Foo class to look in
 > Foo's class pool, not the compiler.

      You're referring to Metaclass>>scopeHas:ifTrue:, which does indeed 
  delegate to the receiver's sole instance. But in that method "scope" 
refers to the scope associated with the intended receiver of the method 
we're compiling (Foo), not the object being asked this scope question 
(Foo class). This doesn't say anything about what the class variables of 
(Foo class) are, only that (Foo class) is responsible for answering the 
class variables of Foo when compiling methods to be run with Foo as 
receiver.

 > > To say otherwise is to introduce a conceptual inconsistency into
 > > the system: the class variables of an object are defined by its
 > > class, except if that object is a metaclass. Further, suppose the
 > > class variables pool for Metaclass were not empty. By your logic
 > > instances of Metaclass don't have access to it.
 >
 > The only place that instances of Metaclass have access to Metaclass's
 > class pool is in methods on Metaclass.

      As I clarified in a followup message, I was referring to what a 
metaclass should answer as its class variables, not how to bind anything 
during compilation of methods for which that metaclass will be the 
receiver (those would just be instance-side methods of Metaclass, as you 
say). For example, having put an entry into the class variables pool for 
Metaclass, if I then ask (Array class) for all its class variable names, 
I won't get the new class variable name in my answer by your logic.

 > Class-side methods in metaclasses other than Metaclass class do _not_
 > have access to Metaclass class variables.  Try it :)

      Eh? I never said that any of those methods should be able to bind 
class variable names from Metaclass. I was talking about what one should 
get when asking a metaclass point-blank for all its class variable names 
(something that never happens as far as I can remember, hence the 
exquisite angels-on-the-head-of-a-pin nature of this conversation :).


-C

--
Craig Latta
improvisational musical informaticist
www.netjam.org
Smalltalkers do: [:it | All with: Class, (And love: it)]




More information about the Squeak-dev mailing list