SBCL 1.3.1
总之,a是一个列表,'(7),b设置为通过相同的列表setq.附加一个值b.列表c设置为追加后的预期结果,即'(7 1).a然后进行比较c并正确比较真实.但是,当a比较via时(equal a '(7 1)),它会比较false.
我的猜测是编译器没有看到追加,就像它已经完成一样b,并且已经将比较优化为常量并且结果不正确.如果是这样,有哪些选项可以提示编译器.可以a某种方式标记为特殊?或者,除了与破坏性编程相关的样式问题之外,还有其他什么东西在这里发生吗?
(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)
Run Code Online (Sandbox Code Playgroud)
这是在空载环境中加载和运行的脚本.该文件是上述代码的复制和粘贴.可以看到没有错误消息.有趣的是,这里看到的结果是不同的.
§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)
*
Run Code Online (Sandbox Code Playgroud)
引用的列表是"文字",修改它们(正如你所做的那样(setf (cdr b) ...))会导致不明确的后果.任何结果test-0都是有效的,例如,格式化硬盘和炸毁你的房子.
替换'(7)为(list 7),你应该得到你期望的.
PS.请正确格式化您的代码.