[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
2 problems
Date: Mon, 23 May 88 10:12:44 EDT
From: bds@mitre-bedford.ARPA
We are running genera 7.2 on 3650's. I've experienced the following 2
problems:
1) Suppose I have the following:
(defvar *a*)
(defvar *b*)
(defun eq-test ()
(let ((a '(a b c d))
(b '(a b c d)))
(setq *a* a)
(setq *b* b)))
After running eq-test, it turns out that *a* and *b* are eq!
This, by the way, occurs with arrays, strings, etc. The only
way to avoid this is to make liberal use of copy-* in these
functions.
See CLtL, p. 78.
2) Suppose I have a structure named rts which is stored as a
named vector. Given an instance of this structure, rts-1,
if I then do (setq rts-2 (copy-rts rts-1)), I find that although
every slot of rts-2 is eq to the corresponding slot in rts-1,
rts-1 and rts-2 are not equal !
Moreover, given that the nominal-equipment-list slot of rts is a list
of equipment structures, I find that
(eq (rts-nominal-equipment-list rts-1)
(rts-nominal-equipment-list rts-2))
returns t, but when I do
(push t (rts-nominal-equipment-list rts-1))
rts-1 is modified but rts-2 is not!
This is exactly what should happen. Perhaps drawing some pictures of
your objects and the relationship between them would help you understand
what was happening:
------------- -------------
rts1 | | | | rts2 | | | |
--+---+---+-- --+---+---+--
| | | | | |
V | | | | |
A <-+---+-----------------+ | |
| | | |
V | | |
B <-+---------------------+ |
| |
V |
C <-----------------------+
Note that RTS1 and RTS2 are not the same object, so they are not EQ.
However, each corresponding slot in RTS1 and RTS2 points to the same
object. When you push something into a slot of RTS2, you only modify
the slot in RTS2, and the slot in RTS1 remains pointing at whatever it
was pointing at before:
------------- -------------
rts1 | | | | rts2 | | | |
--+---+---+-- --+---+---+--
| | | | | |
V | | | | |
A <-+---+-----------------+ | |
| | | |
V | | |
B <-+---------------------+ V
| ---------
| | T | |
| ------+--
V |
C <---------------------------+
(Since you're running 7.2, I could send you real pictures, but the
people on the list using 7.1 would only see garbage characters...)
Thanks for your help.
Barry Smith