我写了以下函数
(defn insert-block
"Given a block, coordinate and playfield, returns the altered playfield.
Does not check for collisions."
[[x y] block playfield]
(let [blocksize (count block)
insertion (fn [a b] (vector (block a) (playfield b)))
block-indicies (range 0 blocksize)
field-indicies (range y (+ y blocksize))]
(map insertion block-indicies field-indicies)))
Block和playfield都是向量的向量。出于某种原因,每次调用此函数时,都会出现以下错误:
#<ClassCastException java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn>
该函数与我的代码中的内容相比有所简化 - “插入”在原始版本中更复杂,但无论如何我都会得到相同的错误。这让我感到疯狂 - 有没有人有任何想法?
编辑:对于[x y]和[[0 0 0] [0 1 0] [1 1 1]],我一直用[2 3]测试它。 Playfield太大而无法在此处粘贴,但它是包含整数的26个向量的向量,长度为14。EDIT2:这是playfield矢量。
[[1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 0 0 0 0 0 0 0 0 0 0 1 1]
[1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1 1 1 1 1 1 1]]
EDIT3:我进一步缩小了它 - 以下代码可行。似乎访问块和playfield向量中的元素是导致问题的原因,但我仍然不知道为什么。
(defn insert-block
"Given a block, coordinate and playfield, returns the altered playfield.
Does not check for collisions."
[[x y] block playfield]
(let [blocksize (count block)
insertion (fn [a b] (vector a b))
block-indicies (range 0 blocksize)
field-indicies (range y (+ y blocksize))]
(map insertion block-indicies field-indicies)))
由于