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

问题描述:

我试图实现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的。

如果有人可以给我一些建议,这将不胜感激。

+0

花了我一段时间,但我确实得到了所有版本的Dice of Doom与Clojure一起工作(尽管我使用compojure而不是家庭网络服务器)。让我知道你是否想看看我是如何做到的。我的代码对于一般发布来说还不够好:( – 2012-01-06 12:27:20

+0

嗨艾德里安,你是否在后面聊天?我在理解如何将CL懒惰移植到懒惰seq上:)... – toofarsideways 2012-01-17 11:57:39

+0

嗨toofarsideways,最好只是给我发电子邮件:我是gmail上的adrian.mouat。让我知道你在哪个国家/时区。 – 2012-01-17 12:15:44

在第二行到最后一行,您正在使用功能list而不是您的参数lst(f (rest list) n)应该是(f (rest lst) n)

+0

谢谢Joost,那是我严重的打字错误。我疯狂地想知道我误解了这个部分。非常感激! – toofarsideways 2012-01-05 15:57:31

+1

是的,这是clojure作为Lisp-1的一个潜在问题(意思是函数和“变量”/参数都占用相同的名称空间)。如果你不能为你的序列命名更有用的东西,那么最好使用clojure标准库的命名约定,并使用“coll”而不是“lst”作为泛型seq'able集合(尽管个人而言,我更喜欢“s”简单的序列和地图上的“m”) – 2012-01-05 20:11:23

+0

对于我自己的怂恿,有人愿意解释为什么用函数替换seq的输入错误会产生异常? clojure.lang.PersistentList是'list'函数的数据形式吗? – 2012-01-05 21:58:54