在常见的lisp中对可选参数使用COND

1 lisp common-lisp optional-parameters

我在编写LISP函数时遇到了一些问题.该功能定义为

(defun foo (arg1 &optional cont))
   (cond ((null arg1) nil)
         ((= 0 cont) arg1)
         ((do_something))
         ((recursive call))))
Run Code Online (Sandbox Code Playgroud)

当我调用函数时,cont一切正常,但是当我用arg1调用它时,返回的错误是:

Error: in ZEROP of (NIL) arguments should be of type NUMBER
Run Code Online (Sandbox Code Playgroud)

我觉得情况有问题((= 0 cont) arg1),你能帮我解决这个问题吗?谢谢

cor*_*ump 7

=功能以及其他一些功能只能使用数字.

EQL当您希望NIL成为有效输入时,您需要使用或更一般的相等比较(等于,等于); 这里,NIL是预期的,因为它是可选参数的默认值.

您还可以提供数字默认值cont:

 ... &optional (cont 0) ...
Run Code Online (Sandbox Code Playgroud)

......如果cont没有理由不是数字,那么这可能是正确的方法.