[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 think that the following is a bug that should be changed:
	    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)

	    I can understand doing constant folding on let-bound vars, but I'm
    not so sure about struct slots.  The usual fix of changing it to:
    (defstruct foo
	    (a (list 0.0 0.0))
	    (b (list 0.0 0.0)))
    fixes the symptoms -- but I do think it's a bug.

What about (defstruct foo (a 'a-val) (b 'b-val))?  Should it cons a new
symbol with the same pname?  You gave it a constant structure (with
QUOTE) which always happens to evaluate to the same thing.  How can the
system know that you want a copy without your telling it so (e.g. with
LIST or COPY-LIST?)