lisp nth函数对cons-cell不起作用

ram*_*mar 1 lisp elisp

如果我的变量是list和cons-cell的组合,如果在lisp中使用nth函数,例如: 当我说它返回2 时
(setq aa '(1 2) )
(nconc aa (+ 1 2))
返回我但当我使用它时抛出错误(1 2 . 3)
(nth 1 aa)
(nth 2 aa )

Rai*_*wig 8

NTH返回第n个(0,1,2 ......)cons小区的汽车.

由于你的第二个cdr不是一个利弊单元,所以得到它的汽车是错误的.

(nthcdr 2 '(1 2 . 3))   returns 3
(last '(1 2 . 3))  returns (2 . 3)
Run Code Online (Sandbox Code Playgroud)

通常,避免使用不正确的列表是个好主意,其中某些单元格的cdr不是缺点或NIL.