[pro] Initialization of shared slots
Didier Verna
didier at lrde.epita.fr
Wed Jan 5 22:08:39 UTC 2011
rm at tuxteam.de wrote:
> On Wed, Jan 05, 2011 at 06:15:34PM +0100, Didier Verna wrote:
>>
>> Tim Bradshaw pointed out that my message was not very clear because the
>> test I gave does not demonstrate that an initform's result is used to
>> initialize the slot early, only at which time a slot is initialized.
>>
>> This on the other hand gets closer to the point:
>>
>> (defclass test ()
>> ((slot :allocation :class :initform t :initarg :slot)))
>>
>> (defmethod initialize-instance :before ((test test) &key)
>> (format t "Slot value: ~A~%" (slot-value test 'slot)))
>>
>>
>> Fresh SBCL:
>> CL-USER> (make-instance 'test)
>> Slot value: T
>> #<TEST {B8115E1}>
>>
>> Fresh SBCL again:
>> CL-USER> (make-instance 'test :slot nil)
>> Slot value: T
>> #<TEST {B92AC89}>
>>
>> So it appears that even when an initarg is provided, the slot is still
>> initialized to the iniform value prior to anything else.
>
> Ecuse my ignorance, but what are you testing? During your second
> make-instance call the (initialize-instance :before ...) method is
> _not_ picking up the initform but the actual slot value from the class
> (remember: slot has class allocation and it's value gets initialized in
> the first invocation of make-instance 'test).
No, I said "Fresh SBCL /again/". SBCL is restarted brand new so that
both of the calls to make-instance above are creating the /first/
instance of that class.
--
Resistance is futile. You will be jazzimilated.
Scientific site: http://www.lrde.epita.fr/~didier
Music (Jazz) site: http://www.didierverna.com
More information about the pro
mailing list