From: Alan Ruttenberg
Subject: quoted lists in compiled code.
Date: 
Message-ID: <1102@mit-amt.MEDIA.MIT.EDU>
In article <···@ntcsd1.UUCP> ···@ntcsd1.UUCP (Michael Smith) writes:
>
>On both a TI and a Sun (using Sun Common Lisp (lucid)), the following occurs:
>
>	>(DEFUN foo1 () '(a b c))
>	>FOO1
>	>(foo1)
>	>(A B C)
>	>(NCONC (foo1) '(d e f))
>	>(A B C D E F)
>	>(foo1)
>	>(A B C D E F)
>
>(DEFUN foo2 () (LIST 'a 'b 'c)) is unaffected in the same situation.

The '(a b c) is stored as a constant in the code, and nconc changes that
constant since it is a destructive operation. In the case of (list 'a b c)
the compiler may constant fold realizing that in the call to list the
arguments never change, so that you might as well do it at compile time.
This is usually a win for performance.

Perhaps compilers ought to make constants in compiled code read only to
protects against this situation.

In any case, to achieve what you want, use

(defun foo () (copy-list '(a b c)))

which guarantees a newly consed list every time.

-alan