[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Another EQ problem
Date: 26 May 88 11:01 EST
From: STERRITT%SDEVAX.decnet@ge-crd.arpa
I have some code that does surgery (setf's of nth's) on lists in
a Defstruct. Since some of the fields are identical, the lists are eq.
This means (obviously, once you know about it) that if you change slot A,
slot B is smashed too!
E.G.:
(defstruct foo
(a '(0.0 0.0))
(b '(0.0 0.0)))
;;compile, then:
(setf bar (make-foo))
(setf (nth 0 (foo-a bar)) 4.5)
(foo-a bar)
-> (4.5 0.0)
(foo-b bar)
-> (4.5 0.0)
Never ever side effect constant structure, unless you want to be really faked
out. Not only will (foo-b bar) be affected if you rplaca (foo-a bar), but
also (foo-a (make-foo)) will ALSO return what you smashed in (foo-a bar).
That's because you have smashed the list that is used to initialize the data
structure.