如何在 LISP 中将列表作为带有 defun 的参数传递?(递归)



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

注意:我相信我也使用不正确的附加。

;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)))

最新更新