我下面的代码是假设添加数字 @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/