Lisp:函数为列表打印 NIL
Lisp : Function prints NIL for list
我 运行 遇到的问题是,当我创建一个函数来打印列表的特定部分时,它会将其打印为 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)
- 为什么在函数中使用列表时打印NIL,但单独使用时它输出第一个元素就很好?
- 如何获得打印列表中我想要的部分的功能?
您有:
(print (car (list)))
这是调用 the list
function,不是 使用您的 list
参数。 (list)
总是 returns 一个空列表。 (Common Lisp 是 "Lisp-2",这意味着函数调用上下文中的 list
与变量访问上下文中的 list
指的是不同的东西。)
要修复,请更改您的代码以使用:
(print (car list))
相反。
我 运行 遇到的问题是,当我创建一个函数来打印列表的特定部分时,它会将其打印为 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)
- 为什么在函数中使用列表时打印NIL,但单独使用时它输出第一个元素就很好?
- 如何获得打印列表中我想要的部分的功能?
您有:
(print (car (list)))
这是调用 the list
function,不是 使用您的 list
参数。 (list)
总是 returns 一个空列表。 (Common Lisp 是 "Lisp-2",这意味着函数调用上下文中的 list
与变量访问上下文中的 list
指的是不同的东西。)
要修复,请更改您的代码以使用:
(print (car list))
相反。