[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

2 problems

I'm not sure why either of these are "problems" except as you may have
depended upon undocumented behaviour which changed:

    Date: Mon, 23 May 88 10:12:44 EDT
    From:     bds@mitre-bedford.ARPA

    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

I don't believe there's anything in common-lisp which prohibits
constant-folding.  If you explicitly want new structure to be consed
each time, you should make that fact explicit:

(defun eq-test ()
  (let ((a (list 'a 'b 'c 'd))
	 (b (copy-list '(a b c d))))
    (setq *a* a)
    (setq *b* b)))

Otherwise there's can't see why it shouldn't improve the performance of
your code.

    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!

Look at page 270 of the Silver book.  Push is equivalent to 
(setf (rts-nominal-equipment-list rts-1) (cons t (rts-nominal-equipment-list rts-1)))
It's a macro.

Look at this example:

(setf foo '(1 2)) => (1 2)
(setf bar foo)    => (1 2)
(eq bar foo)      => t
(push 3 foo)      => (3 1 2)
(eq bar foo)      => nil
(eq bar (cdr foo))=> t

Perhaps what you want is something like the following (only works on

(defun bd-push (elt list)
    (setf (cdr list) (cons (car list) (cdr list))
	  (car list) elt))