我正在尝试使用 substitute-if
。在这里,我尝试将 '((1) (2) (3) (4))
中的所有值替换为 '(0)
[9]> (substitute-if '(0) #'evenp '((1) (2) (3) (4)) :start 1 :key #'car)
((1) #1=(0) (3) #1#)
我对列表中的 #1=(0)
和 #1
感到困惑。我希望它返回 '((1) (0) (3) (0))
。
我是否误解了 substitute-if
的工作原理或误解了列表的表示形式?
最佳答案
Am I misunderstanding how
substitute-if
works or misunderstanding the representation of the list?
可能是后者。
#1=...
标记了数据结构中的一个位置,#1#
指向它。这个想法是为了表明两个元素都引用同一个列表。 (另见 http://www.lispworks.com/documentation/HyperSpec/Body/02_dhp.htm。)
就像:
(let ((x '(0)))
(list '(1) x '(3) x))
因为它们引用同一个对象,所以如果您要修改第二个列表,修改也会显示在第四个列表中。
关于lisp - 列表的 CLISP 表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51118113/