我有这个功能:
(defun test (variable)
(cond
((null variable) nil)
((< (- 12 (other-function variable) 3) 0) 1)
(t (- 12 (other-function variable) 3))
)
)
这个想法是,如果用3的函数的值减去12的结果小于0,则返回1.否则,它将仅进行减法。 “other-function”返回一个数字。 当我运行此功能时,lispworks会冻结。但是,如果我在没有第一个条件的情况下运行该函数:
(defun test (variable)
(cond
((null variable) nil)
(t (- 12 (other-function variable) 3))
)
)
它可以毫无问题地进行减法。 有人可以帮忙吗? 感谢。
修改 我用let:
尝试了这种方式(defun test (variable)
(let (x (other-function variable))
(cond
((null variable) nil)
((< (- 12 x 3) 0) 1)
(t (- 12 x 3)))
)
)
但我仍然遇到与lispworks相同的问题,它冻结了。当我没有以下条件时运行:
((< (- 12 x 3) 0) 1)
此功能正常工作。
答案 0 :(得分:3)
除非您提出完整的代码和测试用例,否则无法复制。
CL-USER 1 > (lisp-implementation-type)
"LispWorks"
CL-USER 2 > (defun test (variable)
(cond
((null variable) nil)
((< (- 12 (other-function variable) 3) 0) 1)
(t (- 12 (other-function variable) 3))))
TEST
CL-USER 3 > (defun other-function (foo) (+ foo 1))
OTHER-FUNCTION
CL-USER 4 > (test 5)
3
CL-USER 5 > (test 500)
1
另外:LispWorks通常不会冻结&#39;出错了。