[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

:class slot allocation



I've just discovered that :class slot allocation in CLOS isn't what I thought
it was, specifically the meaning of sharing a :class slot among instances of
a class and its subclasses. Evidently shared slots are not shared throughout
the class hierarchy, e.g., given

	(defclass foo ()
	  ((baz :allocation :class)))

	(defclass bar (foo))

the slot baz is shared among instances of foo, and among instances of bar,
but not among instance of foo and bar; that is, if I change a foo's baz slot,
the baz slot of any instance of bar doesn't change. 

My apparent misunderstanding of the CLOS spec is undoubtedly colored by my
experience with C++, which has something similar to ":class" allocation: a
C++ class can have a "static" member, which is a shared by all instances of
the class. The difference between C++ and CLOS here is that it is also shared
throughout the hierarchy of that classes subclasses. 

Is there any way to achieve the latter behavior ("static" slot allocation) in
CLOS? Of course I can implement this behavior using global data, but I'd rather
not admit defeat that easily, since this data is really describing a class
attribute. Using the given semantics of :class slots, and explicitly
propogating changes of a shared slot to the corresponding shared slot of the
subclasses and superclasses seems unacceptable. Is a non-standard metaclass
necessary, and if so, is the current CLOS implementation up to it?


tom kirk
tk@moss.att.com


(incidentally, the description of the behavior of :class allocation in the
CLOS spec is very similar to that of static class members in the C++ reference;
I guess, after re-reading it a few times, that the wording in the CLOS spec is
arguably `more correct')