【发布时间】:2021-08-13 12:11:37
【问题描述】:
当我试图检查数字是否等于列表中的任何元素时,我收到以下错误:
'NIL' is not of the expected type 'NUMBER'
(defun check-num (li n)
(cond
((= n (car li)) t)
((not (= n (car li))) (check-num (cdr li) n))
((not (= n (car li))) nil)))
(check-num '(1 2 3 4 5) 6)
我发现当它尝试使用空列表执行函数'check-num'时出现问题,在执行所有检查后输入的数字。
编译器尝试执行以下功能时出现错误:
(check-num nil 6)
【问题讨论】:
-
如果你的函数有可能返回 NIL,那么使用
equal而不是=,它不会失败。 (这是我部署的应用程序中唯一的错误。而且我是一个 lisp 新手。非常好。)
标签: lisp common-lisp