[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Blown Away Slot Initform

paul_hasse@NSDGATE3.nsd.fmc.com (paul hasse) writes:

> Does anybody know if slot initforms can be altered within the class
> definition by side effect, i.e. destructively altering an instance of
> the class.  Does Steel describe this behavior (I cannot find the
> reference).
> As an example, the following code returns => TED
> (progn (defclass person () ((x :initform '(1 2 3)))) 
>	(setf x (make-instance 'person))
>	(setf (car (slot-value x 'x)) 'ted)
>	(setf y (make-instance 'person))
>	(car (slot-value y 'x)))
> Is this a bug in MCL or is this the expected behavior (inquiring minds
> want to know).

This is the expected behavior. If you don't want it to happen,
use the following initform instead, to ensure you get a new list for
each instance instead of one eq to the initform (or just don't
do destructive operations on slot contents):

(defclass person () ((x :initform (list 1 2 3))))

Shannon Spires
Internet: svspire@sandia.gov
Voice: 505-844-4287
Fax: 505-844-3296