【发布时间】:2012-01-05 12:33:14
【问题描述】:
我正在尝试实现Land of Lisp's Dice of Doom game,我得到了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)))
用这个:
(add-new-dice '[(0 1) (1 3) (0 2) (1 1)] 0 2)
我这样做主要是为了让自己熟悉 CL 代码并获得一些将其移植到 Clojure 的经验。
如果有人能给我一些建议,将不胜感激。
【问题讨论】:
-
花了我一段时间,但我确实让所有版本的 Dice of Doom 都与 Clojure 一起工作(尽管我使用的是 compojure 而不是家庭滚动的 Web 服务器)。如果你想看看我是怎么做的,请告诉我。不过,我的代码对于一般发布来说还不够好:(
-
嗨,阿德里安,你以后有空聊聊吗?我在理解如何将 CL 惰性移植到惰性序列时遇到了一些困难:)...
-
嗨,toofsideways,最好只是给我发电子邮件:我是 gmail 上的 adrian.mouat。让我知道你在哪个国家/时区。
标签: exception recursion clojure lisp