为什么我会收到LazySeq投射错误?

Joe*_*oel 2 casting clojure

我写了以下函数

(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))) 
Run Code Online (Sandbox Code Playgroud)

块和游戏区域都是向量的向量.出于某种原因,每次调用此函数时,都会出现以下错误:

#<ClassCastException java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn>
Run Code Online (Sandbox Code Playgroud)

该函数已经从我的代码中简化了一点 - "插入"在原始版本中更复杂,但无论如何我得到相同的错误.这让我感到疯狂 - 有没有人有任何想法?

编辑:我一直用[2]为[xy]和[[0 0 0] [0 1 0] [1 1 1]]测试它.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]]
Run Code Online (Sandbox Code Playgroud)

编辑3:我进一步缩小了它 - 以下代码可行.似乎访问块和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))) 
Run Code Online (Sandbox Code Playgroud)

谢谢

Daa*_*aan 7

我很确定你并没有真正将向量传递给你的函数.它适用于你提供的矢量,使用clojure 1.3.

从clojure中的集合中检索第n个值的更安全的方法是第n个函数.此函数适用于您传入的任何类型的集合,列表,向量,序列等.

正如Joost评论的那样,你的函数返回一个懒惰的序列,这可能不是你想要的.如果你绝对需要向量,你可以将map的结果传递给vec.