3

两个都

(not 'nil)

(not nil)

评估为,那么和T之间有什么区别吗?那么呢?如果评估为,不应该评估为吗?'nilnil''nil''nil'nil''nilnil

4

3 回答 3

8

(quote <anything>)<anything>从字面上看,计算结果为 。符号'<anything>表示(quote <anything>),无论是什么<anything>,它都只是简单地返回而不被评估。

此外,nil对自身进行评估。

其他对象,当引用为文字时,也会对自己进行评估:某些符号和所有非符号原子都是这种方式。

'2和 和有什么不一样2?他们都评价为2

'"abc"另外, and和"abc"之间有什么区别?:foo':foo

不同的是,'2是形式(quote 2),而2只是2。他们评估同一件事,但不是同一件事。

评估 Lisp 意味着将数据视为表达式的源代码。两个表达式可以具有相同的值,但由不同的数据组成。例如和。4_(+ 2 2)(* 2 2)

4说,和有什么区别(+ 2 2)

如果4(+ 2 2)都产生 4,为什么'4产生4,但是'(+ 2 2)产生(+ 2 2)

引用的意思是,“给我这段程序代码作为数据,而不是它所表示的值。”

于 2012-04-04T14:03:02.827 回答
6

When you evaluate NIL you get the value of the variable named NIL, and when you evaluate 'NIL you get the symbol named NIL. However, these two things are defined by the spec to be the same object. See the Hyperspec on nil:

nil n. the object that is at once the symbol named "NIL" in the COMMON-LISP package, the empty list, the boolean (or generalized boolean) representing false, and the name of the empty type.

You can check that for yourself:

(eq NIL 'NIL) ==> T

However, the equivalence stops there. ''NIL evaluates to the list (quote NIL).

于 2012-04-04T12:07:23.050 回答
1

There is no difference, as long as you consider only the result of evaluation, i.e.,

nil

and

'nil

evaluate to the same value (namely, nil). There is, however, a true difference, as far as the reader is concerned, since

nil  ===> nil

whereas

'nil ===> (quote nil)

This is interesting in particular, if you have nested forms like

((nil) 'nil)

which is read as

((nil) (quote nil))
于 2012-04-04T12:07:12.363 回答