Lisp中的嵌套数据列表上的"cdadr" [英] 'cdadr' on nested data list in lisp
问题描述
在研究cons
,cdr
和car
来处理列表时,我尝试了以下操作:
While studying cons
, cdr
and car
to handle lists I tried following :
(cadr '('(1) '(2)))
'(2)
,将按预期显示列表中的第二项. 而以下给出:
which gives the second item in the list as expected. Whereas following gives :
(cdadr '('(1) '(2)))
((2))
如何使数据与代码一致,但仍不出错?
How is data being concerted to code and still not giving error?
这是如何评估的?
cdr应该为nil,确实如此.为什么不在上方?
cdr on '(2) should give nil, which is does. Why not above?
[我对clisp和stackoverflow都是陌生的,所以请原谅我.]
[I am new to both clisp and stackoverflow so pardon me.]
推荐答案
quote
是特殊运算符它返回其单个未评估的参数.可以使用 '
作为'...
来缩写形式(quote ...)
.由于'
由读者处理,因此表单
quote
is a special operator which returns its single unevaluated argument. The form (quote ...)
can be abbreviated using '
as '...
. Since the '
is handled by the reader, the form
'('(1) '(2)))
的读法实际上与
(quote ((quote (1)) (quote (2)))
参数((quote (1)) (quote (2)))
的最外层应用程序quote
返回该参数.该参数的cadr
是列表
The outermost application quote
to the the argument((quote (1)) (quote (2)))
returns that argument. The cadr
of that argument is the list
(quote (2))
第一个元素是符号quote
,第二个元素是单个元素2
的列表.
whose first element is the symbol quote
, and whose second element is a list of a single element 2
.
这篇关于Lisp中的嵌套数据列表上的"cdadr"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!