[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Blown Away Slot Initform
- To: info-mcl@digitool.com
- Subject: Re: Blown Away Slot Initform
- From: Shannon V Spires <svspire@somnet.sandia.gov>
- Date: Tue, 21 Feb 1995 13:40:31 -0700 (MST)
- In-reply-to: <199502210900.BAA11391@digitool.com> from "info-mcl-digest-request@digitool.com" at Feb 21, 95 01:00:03 am
- Sender: owner-info-mcl@digitool.com
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