Metaclasses?

Craig Latta craig at netjam.org
Thu Oct 14 08:49:36 UTC 2004


Hi--

	Michael van der Gulik writes:

> Symbol class = Metaclass (print it...)---> false.
> 
> and...
> 
> [Symbol class isKindOf: Class] ---> false.
> [Metaclass isKindOf: Class] ---> true.
> 
> Hmm.. but if I inspect [Symbol class], I'm looking at Metaclass.
> 
> Could somebody explain this to me please?

	I suspect what confused you was the inspector window label, when you
browsed (Symbol class). Currently, an inspector label uses the name of
the class of the object you're inspecting. When you're inspecting
(Symbol class), you're looking at a Metaclass, not Metaclass itself.
Unfortunately, the label of the inspector was "Metaclass", which I think
is quite misleading. A better label would be "a Metaclass", or, better
yet, "Symbol class". Strictly speaking, each metaclass has no name, but
it is strongly associated with something that does, and the tools ought
to show that.

	In general, I'd prepend the appropriate article in each inspector
label. That would usually be "a" or "an", but for instances of
metaclasses I'd use "the" (e.g., "the Symbol class"), since typically
each metaclass has only one instance.

	Also, note that a typical contemporary Smalltalk system actually has no
instances of Class. Print (Class allInstances size) to see this. Rather,
it has instances of subclasses of Class. In particular, each metaclass
is a subclass of Class. The most helpful cue about this that you'll get
from the typical Squeak tools is by browsing the Behavior class and
choosing "show hierarchy".


-C

p.s.

	Brian Murphy-Dye writes:

> There is a little magic that goes on at this point because there is
> a chicken and egg problem: the 'Class' class can't exist without the 
> Class instance and Class metaclass, yet how can you have a Class 
> instance until the Class class exists? I haven't looked into how
> Squeak solves this...

	There is an instantiation circularity between Metaclass and (Metaclass
class). Metaclass is the instance of (Metaclass class), and (Metaclass
class) is an instance of Metaclass. I don't know if you meant to imply
that Class is involved in the circularity, but it is not. Class is
simply an instance of (Class class), which in turn is an instance of
Metaclass. Well, I use the word "simply" advisedly. :)

	The fact that all the metaclasses are subclasses of Class is arguably
odd at first glance, but not circular. People tend to say "a Foo" when
they're talking about an instance of Foo *or* one of its subclasses.
That would make "Symbol is a Class" literally true, since Symbol is an
instance of something that is a subclass of Class. Perhaps this led to
your phrasing above. I think each time you said "Class instance"
throughout your message, you meant "an instance of a Metaclass".

	As for how the circularity is actually created: the class of an object
is stored in its header bits, and you can fiddle with those, just like
anything on your computer. :)  For details, see the virtual machine
implementation. A good starting point would be
ObjectMemory>>fetchClassOf:. Run the simulator. Then run (WarpBlt
test3).  :)

	You might find http://netjam.org/objectMetaphysics interesting. And
there are several object systems without classes at all; see, for
example, http://research.sun.com/research/self/.

	For some reason, I write this message about every three years. I hope
it helped; this has been a recording. :)

--
Craig Latta
improvisational musical informaticist
craig at netjam.org
www.netjam.org
[|] Proceed for Truth!




More information about the Squeak-dev mailing list