[英]Scheme and R5RS questions about eq
Can you explain why the first one is false and the second one is true?你能解释为什么第一个是假的,第二个是真的吗?
And how this works?这是如何运作的? Thanks.谢谢。
(eq? '(1 2 3) '(1 2 3)) ;False
(eq? '() '()) ;True
There's only one empty list, so all uses of ()
refer to that list, and it's eq?
只有一个空列表,所以()
所有用法都是指那个列表,它是eq?
to itself.给自己。 The Scheme Specification description of the storage model says:存储模型的方案规范描述说:
Notwithstanding this, it is understood that the empty list cannot be newly allocated, because it is a unique object.尽管如此,可以理解的是,空列表不能重新分配,因为它是唯一的对象。
and the specification of eqv?
和eqv?
的规格eqv?
(which is referenced by the eq?
description) says that two objects are equivalent if (由eq?
描述引用)说两个对象是等价的,如果
obj 1 and obj 2 are both the empty list obj 1和obj 2都是空列表
But when you create a non-empty list, it creates a fresh one every time, and they're not eq?
但是当您创建一个非空列表时,它每次都会创建一个新列表,并且它们不是eq?
to each other even if they contain the same elements.即使它们包含相同的元素。
[..] Two objects are considered identical if they are represented internally by the same pointer value [..] The empty list () is identical to itself wherever it appears. [..] 如果两个对象在内部由相同的指针值表示,则认为它们是相同的 [..] 空列表 () 无论出现在何处都与其自身相同。 [..] Two pairs, vectors, or strings created by different applications of cons, vector, string, etc., are distinct. [..] 由 cons、vector、string 等的不同应用创建的两对、vector 或 strings 是不同的。
If you write instead如果你改写
(let ((x '(1 2 3)))
(eq? x x))
it will be #t
.它将是#t
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.