我是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 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)))运行得很好,我确信我的函数也会做同样的检查。所以。我不明白这个错误发生在哪里,为什么会发生。
发布于 2013-04-26 17:09:53
您确定在此函数中发生错误吗?你应该看看回溯。
此外:
(setf (symbol-function 'reduce-our)
#'(lambda (new-expression)
...))通常写成
(defun reduce-our (new-expression)
...)然后:
(setf (symbol-function 'reduce-our)
#'(lambda(new-expression)
(setf expression nil) ...变量expression是在哪里引入的?它是未声明的。设置该值不会声明变量。
然后:
while (not (foo ...))就是
until (foo ...)和
(if (not (foo)) a b)是
(if (foo) b a)另外:改进缩进。Lisp中的编辑器将为您做这件事。它增加了你和其他人的可读性。
https://stackoverflow.com/questions/16230566
复制相似问题