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

Re: Damaged literals?



At 2:57 PM 9/30/94, paul hasse wrote:
 >In the following function, I replace two elements in a list....
 >
 >? (defun test ()
 >    (let ((x '(1 2 3 4 5 6 7 8 9)))

Yes, there's a subtle but important difference between that and

(defun test ()
  (let ((x (list 1 2 3 4 5 6 7 8 9)))
    ...

Your example creates one literal at compile time, and modifies it
with setf. Think of it as re-entering the same code for your test
function every time you invoke it. That list is right there inside
the compiled code for your test function.

If you type '(1 2 3) in the listener twice, it creates two different 
(equal, but not eq) lists, because they're not "in the same place".
My version conses a fresh list every time.

 >? (defun test ()
 >    (let (x)
 >      (setf x '(1 2 3 4 5 6 7 8 9))

The problem here is not let versus setf, but the difference between
a quoted literal and using list to create a fresh new copy each time.