I have a class (my-class) with many subclasses, that use a shared
slot, draw-color. So, each instance of my-class or its subclasses can
access the shared value of draw-color. But, how can I obtain the
value of draw-color given a class-name?
From what I've read in CLtL2, a shared slot is stored with the class
rather than the instance.
28.1.3.2. Inheritance of Slots and Slot Options
"If the value of the :allocation slot option is :instance, then S is a
local slot and each instance of C has its own slot named S that stores
its own value. If the value of the :allocation slot option is :class,
then S is a shared slot, the class that defined S stores the value,
and all instances of C can access that single slot."
So can I access its value without an instance? I think I see how to
get the initform using slot-definition-initform, but not the shared
value.
Cheers......
Kev
--------------------------------Bermuda Massive
Kevin Mayall ·······@uwaterlooREMOVETHIS.ca
School of Planning
University of Waterloo
In article <················@news.uwaterloo.ca>,
<·······@uwaterlooREMOVETHIS.ca> wrote:
>So can I access its value without an instance? I think I see how to
>get the initform using slot-definition-initform, but not the shared
>value.
No, there's no standard way to access the shared slot without an instance.
I think the MOP specifies that a class should have a "representative
instance", and there's a method on the class that returns it (I can't find
my copy of AMOP, so I can't be more specific), so you may be able to access
shared slots through this.
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
In article <················@news.uwaterloo.ca>, ·······@uwaterlooREMOVETHIS.ca writes:
>> I have a class (my-class) with many subclasses, that use a shared
>> slot, draw-color. So, each instance of my-class or its subclasses can
>> access the shared value of draw-color. But, how can I obtain the
>> value of draw-color given a class-name?
>>
>> From what I've read in CLtL2, a shared slot is stored with the class
>> rather than the instance.
>> So can I access its value without an instance? I think I see how to
>> get the initform using slot-definition-initform, but not the shared
>> value.
>>
This is really a hole in the standard IMO. I'd personally like to
see the function #'class-slot-value be defined, which is
what I use in my programs.
(defun class-slot-value (class slot-name)
(when (not (clos::class-finalized-p class))
(clos::finalize-inheritance class))
(slot-value (clos:class-prototype class) slot-name))
-Kelly Murray ···@franz.com