Common lisp 常见lisp错误:该值不是预期的类型编号
我是lisp新手,在功能上有一些问题:Common lisp 常见lisp错误:该值不是预期的类型编号,common-lisp,Common Lisp,我是lisp新手,在功能上有一些问题: (setf (symbol-function 'reduce-our) #'(lambda(new-expression) (setf expression nil) (loop while (not (equal new-expression expression)) do (setf expression new-expression)
(setf (symbol-function 'reduce-our)
#'(lambda(new-expression)
(setf expression nil)
(loop while (not (equal new-expression expression)) do
(setf expression new-expression)
(setf new-expression (reduce-once-our expression))
(if (not (equal 'new-expression 'expression))
(format t " ==> ~A Further reductions are impossible.~%"
new-expression)
new-expression))))
(reduce-our '(^ x => x))
这将导致下一个错误:
Error: The value ^ is not of the expected type NUMBER.
我以为lisp试图在while循环中评估我的输入列表,但是
(not (equal nil '(^ x => x)))
工作正常,我确信我的函数也会进行同样的检查。所以我不明白此错误发生的位置和原因。您确定此错误发生在该函数中吗?你应该看看回溯 此外:
(setf (symbol-function 'reduce-our)
#'(lambda (new-expression)
...))
通常写为
(defun reduce-our (new-expression)
...)
然后:
变量表达式
在哪里引入?这是未申报的。设置该值不会声明变量
然后:
只是
until (foo ...)
及
是
另外:改善压痕。Lisp中的编辑器将为您执行此操作。它增加了您和其他人的可读性。或者,如果您正在使用的Common Lisp的实现没有内置编辑器,我建议您考虑使用Emacs或Vim作为编辑器。两者都带有Lisp漂亮的打印功能。您还可以找到一个用Lisp编写的Lisp pretty打印机脚本。
while (not (foo ...))
until (foo ...)
(if (not (foo)) a b)
(if (foo) b a)