我遇到的问题是,当我创建一个打印列表某个部分的函数时,它会将其打印为NIL而不是实际的元素.
例如:
> (setf thelist '((a b) (c (d e f)) (g (h i)))
> (defun f1(list)
(print ( car (list))))
> (f1 thelist)
NIL
NIL
But this works:
> (car thelist)
(A B)
Run Code Online (Sandbox Code Playgroud)
Chr*_*ung 11
你有:
(print (car (list)))
Run Code Online (Sandbox Code Playgroud)
这是调用的list函数,而不是使用list参数.(list)总是返回一个空列表.(Common Lisp是一个"Lisp-2",这意味着list在函数调用上下文中指的是与list变量访问上下文不同的东西.)
要修复,请更改要使用的代码:
(print (car list))
Run Code Online (Sandbox Code Playgroud)
代替.