SBCL 1.3.1
In summary, a is a list, '(7), b is set to the same list via setq. A value is appended to b. List c is set to the expected result after the append, i.e. '(7 1). a is then compared to c and correctly compares true. However, when a is compared via (equal a '(7 1)), it compares false.
My guess is that the compiler has not seen the append, as it was done on b, and has optimized away the compare to constant with the incorrect result. If so, what options are there to tip off the compiler. Can a be marked as special somehow? Or, apart from style issues related to destructive programming, is there something else going on here?
(defun test-0 ()
(let ((a '(7))
b
(c '(7 1)))
(setq b a)
(setf (cdr b) (cons 1 '()))
(pprint (list a b c))
(values (equal c a) (equal '(7 1) a) (equal (list 7 1) a) c a)))
* (test-0)
((7 1) (7 1) (7 1))
T
NIL <== ??
T
(7 1)
(7 1)
Here is the transcript as it is loaded and run in an empty environment. The file is a copy and paste of the code above. One can see that there are no error messages. It is interesting to see here that the results are different.
§sbcl> sbcl
This is SBCL 1.3.1.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (load "src/test-0")
T
* (test-0)
((7 1) (7 1) (7 1))
NIL
NIL
T
(7 1)
(7 1)
*