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

Damaged literals?



In the following function, I replace two elements in a list.  Notice that in 
the second run of this function, x is not initialized to '(1 2 3 4 5 6 7 8 9), 
rather it retains its modified form from the previous execution of test.  Can 
someone direct me to the pages in Steele (2nd edition) which refer to this 
behavior.  I did not expect this but I doubt it is a bug in MCL but rather a 
subtle behavior I am not aware of.

? (defun test ()
    (let ((x '(1 2 3 4 5 6 7 8 9)))
      (print x)
      (setf (fourth x) 'four)
      (print x)
      (setf (ninth x) 'nine)
      (print x)))
TEST
? (test)
(1 2 3 4 5 6 7 8 9) 
(1 2 3 FOUR 5 6 7 8 9) 
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE)
? (test)
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE)
? 

Notice that the same results are had with the variation of test which uses a 
setf to initialize x rather than the let.

? (defun test ()
    (let (x)
      (setf x '(1 2 3 4 5 6 7 8 9))
      (print x)
      (setf (fourth x) 'four)
      (print x)
      (setf (ninth x) 'nine)
      (print x)))
TEST
? (test)
(1 2 3 4 5 6 7 8 9) 
(1 2 3 FOUR 5 6 7 8 9) 
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE)
? (test)
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE) 
(1 2 3 FOUR 5 6 7 8 NINE)
?