得到一个不知道如何创建一个ISeq:clojure.lang.PersistentList $ 1

too*_*ays 3 lisp recursion exception clojure

我正在尝试实施Land of Lisp's Dice of Doom游戏,而我正在获得一个Don't know how to create ISeq from: clojure.lang.PersistentList$1.

它在调用我的add-new-dice函数时发生:

(defn add-new-dice [board player spare-dice]
  (letfn [(f [lst n]
            (cond (empty? lst) nil
                  (zero? n) lst
                  :else (let [current-player (first (first lst))
                              current-dice (first (rest (first  lst)))]
                          (if (and (= current-player player) (< current-dice *max-dice*))
                            (cons (list current-player (+ current-dice 1))
                                  (f (rest lst) (- n 1)))
                            (cons (first lst) (f (rest list) n))))))]
    (f board spare-dice)))
Run Code Online (Sandbox Code Playgroud)

有了这个:

(add-new-dice '[(0 1) (1 3) (0 2) (1 1)] 0 2)
Run Code Online (Sandbox Code Playgroud)

我这样做主要是为了熟悉CL代码并获得将其移植到Clojure的一些经验.

如果有人能给我一些建议,我们将不胜感激.

Joo*_*aat 8

你在倒数第二行使用函数list而不是你的参数lst.(f (rest list) n)应该(f (rest lst) n)