gpt4 book ai didi

common-lisp - Common Lisp 的复制树 : Which objects will be referenced in common by the original and the copy?

转载 作者:行者123 更新时间:2023-12-04 02:46:10 28 4
gpt4 key购买 nike

我正在阅读 Practical Common Lisp ,并且对 Lisp 的 COPY-TREE 函数有疑问。

书中给出了调用的例子

(copy-tree '( '(1 2) '(3 4) '(5 6)))

在解释之后,本书做出这样的声明:

Where a cons cell in the original referenced an atomic value, the corresponding cons cell in the copy will reference the same value. Thus, the only objects referenced in common by the original tree and the copy produced by COPY-TREE are the numbers 5, 6, and the symbol NIL.

但这对我来说没有意义。我认为 所有原子 将在原始原子和新原子之间共享。因此,我预计 1、2、3、4、5、6 和 NIL 都将在原始和副本之间共享,并且唯一的“新对象”将是所有 CONS 单元格。

哪一个是正确的,为什么?

谢谢。

最佳答案

我查看网页版、pdf 版和精装本。正如你所说,前两个是错误的。精装书说明了这一点(粗体强调是我的):

Where a cons cell in the original referenced an atomic value, the corresponding cons cell in the copy will reference the same value. Thus, the only objects referenced in common by the original tree and the copy produced by COPY-TREE are the numbers 1-6, and the symbol NIL.

所以精装书是正确的。

关于common-lisp - Common Lisp 的复制树 : Which objects will be referenced in common by the original and the copy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12716371/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com