On Wed, Mar 10, 2010 at 6:43 PM, Alan Ruttenberg alanruttenberg@gmail.com wrote:
Hi,
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[1]. 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.
Alessio
[1] http://www.lispworks.com/documentation/HyperSpec/Body/f_shared.htm
-Alan
http://www.franz.com/support/documentation/8.2/doc/mop/dictionary.html#class...
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@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel