blake at mcbride.name
Wed Mar 10 19:32:25 UTC 2010
Here is how to do it in SBCL. cv? represent class variables. iv?
represent instance variables. Both associated to the "class1" class.
(defclass meta-class1 (standard-class)
(cv1 cv2 cv3)
(defmethod sb-mop:validate-superclass ((class meta-class1) (superclass
(defclass class1 (standard-object)
(iv1 iv2 iv3)
(setf (slot-value (find-class 'class1) 'cv2) 'hello)
(slot-value (find-class 'class1) 'cv2)
On Wed, Mar 10, 2010 at 1:11 PM, Alessio Stalla <alessiostalla at gmail.com> wrote:
> On Wed, Mar 10, 2010 at 6:43 PM, Alan Ruttenberg
> <alanruttenberg at gmail.com> wrote:
>> Thanks for adding class-prototype. Unfortunately I realize that the
>> specification doesn't guarantee the behavior I was looking for, so I
>> though I would solicit advise.
>> Basically I want to be able to access class-allocated slot values
>> before I create any real instances. I thought I could grab the class
>> prototype and do slot value on them, but according to the doc below
>> initialize is not called, which I guess is when class-allocated slots
>> are being set up.
>> Is there a portable way of asking for the values of class slots absent
>> the creation of at least one initialized instance?
> I'm afraid there isn't, because all slots (both instance- and
> class-allocated) are initialized by shared-initialize, as part of the
> instance initialization protocol. Also note that, as you posted,
> according to AMOP "The results are undefined if a portable program
> modifies the binding of any slot of prototype instance", so
> initializing its slots in any way, even class-allocated ones, is not
> portable. You should use mop::allocate-instance instead of
> class-prototype. For the record, in ABCL the two are equivalent, but
> e.g. in SBCL they aren't (the class prototype is cached).
> AFAIK, class-prototype is only useful when you have to call a method
> specialized on a class C, but which does not use the object of class C
> in any way except for actually selecting the correct method. With
> class-prototype, you have an option to call such a method even without
> an instance of C available.
>  http://www.lispworks.com/documentation/HyperSpec/Body/f_shared.htm
>> Generic Function class-prototype class
>> Returns a prototype instance of class. Whether the instance is
>> initialized is not specified. The results are undefined if a portable
>> program modifies the binding of any slot of prototype instance.
>> This generic function signals an error if class has not been finalized.
>> armedbear-devel mailing list
>> armedbear-devel at common-lisp.net
> armedbear-devel mailing list
> armedbear-devel at common-lisp.net
More information about the armedbear-devel