I agree with the comments of Set and Vsevolod that this behavior is related to your modification of literal data. Try using (list 0) instead of '(0) . Issues related to this are relatively common, so I'll list HyperSpec here.
3.7.1 Changing letter objects :
The consequences are: undefined if literal objects are destructive modified.
definition of "literal" :
literal adj. (of an object) directly referenced in the program than calculated by the program; that is, as data in the form of a quote or, if the object is a self-evaluating object, appears as unquoted data. `` In the form of (cons "one" '("two")), the expressions "one", ("two") and "two" are literal objects. ''
Please note that often (in many implementations), if you change the values ββof the literal value, you really modify them in the code itself - write the self-editing code. Your sample code will not work as you expect.
Example code in CCL:
CL-USER> (defun modify (a) (setf (car a) 123)) MODIFY CL-USER> (defun testit () (let ((a '(0))) (print (car a)) (modify a) (print (car a)))) TESTIT CL-USER> (testit) 0 123 123 CL-USER> (testit) 123 123 123
Take a look at the second testit evaluation, where let itself already contains the modified value, so the first print also gives 123 .
Also see Lisp, cons and (number number) difference , where I explained this in more detail or the question related to Vsevolod's comment above.
danlei
source share