From: ·······@uwaterlooREMOVETHIS.ca
Subject: access slot with classname?
Date: 
Message-ID: <3502c9d9.9582452@news.uwaterloo.ca>
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

From: Barry Margolin
Subject: Re: access slot with classname?
Date: 
Message-ID: <YUEM.7$Rf5.374123@cam-news-reader1.bbnplanet.com>
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.
From: Kelly Murray
Subject: Re: access slot with classname?
Date: 
Message-ID: <6ed2uv$dha$1@news2.franz.com>
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