【发布时间】:2015-05-05 10:53:45
【问题描述】:
我希望快速修复我的代码,该代码接受数字列表、数字列表和阈值,并返回数字列表中大于阈值的项目数。我就是不知道出了什么问题,而且我对调试也不熟悉。我对stackoverflow很陌生,一般来说LISP......任何cmets /批评/建议都将受到欢迎。谢谢!
ex) (count-greater-than (list 1 2 3 4 5 6 6 7) 5) => 3
(defun count-greater-than (numberlist threshold)
(if (null numberlist) 0
(counter (numberlist threshold 0)))
(defun counter (numberlist threshold count)
(cond ((null numberlist) count)
((> (first numberlist) threshold) (counter (rest numberlist) threshold (+ 1 count)))
(t (counter (rest numberlist) threshold count)))))
【问题讨论】:
-
检查括号。只有一个顶级函数,而另一个函数以某种方式包含在第一个函数中?这看起来很奇怪。创建两个独立的函数。
-
@RainerJoswig 我想知道是否打算创建一个本地递归函数,例如,使用 labels。
-
@RainerJoswig 谢谢。我才意识到这就是问题所在;现在它正在工作。谢谢! (如何将这个问题称为“已解决”?)
标签: debugging lisp common-lisp