Lisp函数调用错误 [英] Lisp function call error
本文介绍了Lisp函数调用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了这样的Lisp函数:
I've written a Lisp function like this:
(defun power (base exponent)
(if (= exponent 0)
1
(* base (power (- exponent 1)))))
但是,当我尝试调用它时,出现一些错误:
When I try to call it, however, I get some errors:
CL-USER 2 > (power 2 3)
Error: POWER got 1 arg, wanted at least 2.
1 (abort) Return to level 0.
2 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 3 : 1 > (power 2)
Error: POWER got 1 arg, wanted at least 2.
1 (abort) Return to level 1.
2 Return to debug level 1.
3 Return to level 0.
4 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 4 : 2 > (power 2 3 4)
Error: POWER got 3 args, wanted 2.
1 (continue) Ignore the extra arg.
2 (abort) Return to level 2.
3 Return to debug level 2.
4 Return to level 1.
5 Return to debug level 1.
6 Return to level 0.
7 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
这是怎么回事?如果我给它两个论点,它就认为我给了它一个.如果我给它三个,它认为我给了它三个.如果我给它一个,它认为我给了它一个...
What's going on here? If I give it two arguments, it thinks I gave it one. If I give it three, it thinks I gave it three. If I give it one, it thinks I gave it one...
推荐答案
这是只有一个参数的递归调用:
It is the recursive call that only has one argument:
(power (- exponent 1))
应该是这样的:
(power base (- exponent 1))
这篇关于Lisp函数调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文