gpt4 book ai didi

exception - 不知道如何从 : clojure. lang.PersistentList$1 创建 ISeq

转载 作者:太空宇宙 更新时间:2023-11-03 18:41:38 25 4
gpt4 key购买 nike

我正在尝试实现 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 的经验。

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

最佳答案

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

关于exception - 不知道如何从 : clojure. lang.PersistentList$1 创建 ISeq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8742541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com