Common Lisp的副本树:原始对象和副本将共同引用哪些对象? [英] Common Lisp's copy-tree: Which objects will be referenced in common by the original and the copy?

查看:90
本文介绍了Common Lisp的副本树:原始对象和副本将共同引用哪些对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读实用的普通Lisp ,并对Lisp的 COPY-TREE 函数。

I'm reading Practical Common Lisp, and have a question about Lisp's COPY-TREE function.

本书提供了调用示例

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

在解释之后,该书将声明如下:

After explaining it, the book makes this statement:


其中原始的con单元格为如果引用一个原子值,则副本中的
对应的con单元格将引用相同的值。
因此,原始树和由COPY-TREE生成的副本中的
共同引用的唯一对象是数字5、6和符号
NIL。

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单元。

But that doesn't make sense to me. I thought all atoms would be shared between the original and the new. Therefore, I expected that 1, 2, 3, 4, 5, 6 and NIL would all be shared between the original and the copy, and that the only "new objects" would be all the CONS cells.

哪个是正确的,为什么?

Which one is correct, and why?

谢谢。

推荐答案

我检查了Web版本,pdf版本和精装本。如前所述,前两个是错误的。精装书指出了这一点(粗体强调是我的):

I check the web-version, a pdf version and the hard cover. The first two are wrong as you state. The hard cover states this (bold emphasis is mine):


如果原始表中的con单元格引用了原子值,则相应的cons单元格在副本中将引用相同的值。因此,原始树和COPY-TREE产生的副本唯一引用的对象是数字 1-6 和符号NIL。

因此精装书是正确的。

这篇关于Common Lisp的副本树:原始对象和副本将共同引用哪些对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆