[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

	    First, let me give Barry Smith (bds@mitre-bedford.ARPA) BIG THANKS
    for posting his "2 Problems" mail with the eq-test program.  It solved a
    bug by analogy, and saved me *much* time and aggravation.
	    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!

It's not constant-folding the defstruct, it's constant-folding the
constructor MAKE-FOO.  I don't think it's unreasonable for a compiler 
to do this.

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

	    --chris sterritt