problem with class variables in stklos
STklos provides a `:class' slot allocation, for data which is
associated with particular classes but not with their instances.
However, as far as I can tell, it isn't possible to set the value of a
given class's slot without creating an instance of the class! (Well,
you could do it by groping about in the class data structure, but it'd
be awful.)
This seems philosophically wrong (given that the class variable is not
supposed to be associated with any particular instance), as well as
inefficient (for example, if the instances are complex widgets, and
you need to create one just to set the slot and then throw it away).
Is there a way to set class variables without creating instances?
I've been doing it by defining instance slots on metaclasses (so that
each class descended from a class with the given metaclass gets its
own value for the slot), and I've overridden define-class to allow me
to set these slots:
(define-class <My-Metaclass> (<Class>)
((class-nickname :init-keyword :class-nickname)))
(define-class <My-Object> (<Object>)
()
:metaclass <My-Metaclass>
:class-nickname 'fred)
(define-class <My-Other-Object> (<My-Object>)
()
:class-nickname 'jane)
... but I'm not sure this is the right thing.
It's also possible to simulate class slots with methods:
(define-method class-nickname ((instance <My-Class>))
'fred)
... but that also seems awkward to.
Is there an approved way of doing class slots? Could it be made
possible to set `:class'-allocated slots in define-class rather than
having to create an instance first?
--Erik
Received on Thu Sep 05 1996 - 09:29:01 CEST
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST