recursion - 如何在 LISP 中将列表作为参数传递给 defun? (递归地)

标签 recursion lisp

我下面的代码是假设添加数字 @n 直到 20@myList。我试图将一个列表作为参数传递给递归函数,但我的语法不正确。我该怎么做?

注意:我相信我也错误地使用了 append。

;Add numbers from @n til 20 to @myList
(defun someFunction(myList, n)
    (if (= n 20) ;Base case, return 20
        20
    )
    (append myList n) ;Append n to the end of myList
    (someFunction myList (+ n 1))
)

最佳答案

虽然不是您关于错误在哪里的确切问题的答案,但为什么不这样:

(ql:quickload :alexandria)
(defun some-function (list start end)
  (append list (alexandria:iota (- (1+ end) start) :start start)))

关于recursion - 如何在 LISP 中将列表作为参数传递给 defun? (递归地),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44036875/

相关文章:

scala - 递归函数中的多态 scala 返回类型

algorithm - 是否有没有递归形式的算法特征?

c++ - 为什么这个递归程序有效?

python - 索引错误: String Index out of range for recursive function

c - 获取我用 C 编写的 Lisp 解释器的流控制警告

com - 是否有开源的 Common Lisp COM 包装器?

lisp - 有人可以用一些例子向我解释 LISP 中 Apply 和 Eval 之间的区别吗?

scheme - 尾递归中的反向输出

c# - 递归快速排序遇到 StackOverflowException

haskell - Y-Combinator 是 monad 吗?