如何在LISP中使用defun传递列表作为参数? (递归的)

时间:2017-05-18 00:46:35

标签: recursion lisp

我的代码假设将@n20添加到@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))
)

1 个答案:

答案 0 :(得分:1)

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

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