Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception 获得don';我不知道如何从clojure.lang.PersistentList$1创建ISeq_Exception_Recursion_Clojure_Lisp - Fatal编程技术网

Exception 获得don';我不知道如何从clojure.lang.PersistentList$1创建ISeq

Exception 获得don';我不知道如何从clojure.lang.PersistentList$1创建ISeq,exception,recursion,clojure,lisp,Exception,Recursion,Clojure,Lisp,我正在尝试实现,我得到了一个不知道如何从以下位置创建ISeq:clojure.lang.PersistentList$1 在调用my添加新骰子函数时发生: (defn add-new-dice [board player spare-dice] (letfn [(f [lst n] (cond (empty? lst) nil (zero? n) lst :else (let [current-p

我正在尝试实现,我得到了一个
不知道如何从以下位置创建ISeq:clojure.lang.PersistentList$1

在调用my
添加新骰子
函数时发生:

(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)))
我这样做主要是为了熟悉CL代码,并获得一些将其移植到Clojure的经验


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

您使用的是函数
列表
,而不是倒数第二行的参数
lst
<代码>(f(rest list)n)应该是
(f(rest lst)n)

谢谢Joost,那是我一个严重的愚蠢的打字错误。我疯狂地想知道我误解了其中的哪一部分。非常感谢!是的,这是clojure作为Lisp-1的一个潜在问题(意味着函数和“变量”/参数都占用相同的名称空间)。如果您不能将序列命名为更有用的名称,那么最好使用clojure标准库的命名约定,并使用“coll”而不是“lst”来表示一般的序列集合(尽管就个人而言,我更喜欢使用“s”表示普通序列,使用“m”表示映射)出于我自己的启发,是否有人愿意解释为什么用函数替换seq的打字错误会产生给定的异常?clojure.lang.PersistentList是
列表
函数的数据形式吗?我相信这是完全正确的Alex,我将函数视为列表(
(rest list)
)。。。乔斯特:谢谢,我想我会的@亚历克斯:这不是clojure.lang.PersistentList,而是clojure.lang.PersistentList$1——这是clojure.lang.PersistentList/creator函数/方法thingy的类。我花了一段时间,但我确实用clojure获得了所有版本的Dice of Doom(尽管我使用的是compojure而不是home rolled web服务器)。如果你想知道我是怎么做的,请告诉我。不过,我的代码还不够好,不适合发布:(嗨,阿德里安,你有空稍后再聊吗?我在理解如何将CL惰性转化为懒惰seq:)时遇到了一些初期困难…嗨,太远了,最好给我发个电子邮件:我是gmail上的Adrian.mouat。让我知道你在哪个国家/时区。
(add-new-dice '[(0 1) (1 3) (0 2) (1 1)] 0 2)