[pro] Initialization of shared slots

Didier Verna didier at lrde.epita.fr
Wed Jan 5 17:15:34 UTC 2011


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.

-- 
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