尝试自学一些clojure,正在使用play-clj。我不明白为什么会这样:
(defn add-shape
[x y entities]
(write-state [x y])
(conj entities (o-shape x y)))
虽然没有:
(defn add-shape
[x y entities]
(conj entities (o-shape x y)
(write-state [x y]))
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException:No implementation of method: :draw-entity! of protocol: #'play-clj.entities/Entity found for class: java.lang.Long
这是两个相关的功能:
(defn x-shape
[x y]
(shape :line
:line (- x 100) (- 600 100 y) (+ x 100) (- (+ 600 100) y)
:line (- x 100) (- (+ 600 100) y) (+ x 100) (- 600 100 y)))
(defn write-state
[arg]
(dosync (alter state conj arg)))
答案 0 :(得分:2)
非常确定你在第二个中有错位的paren。试试这个:
(defn add-shape
[x y entities]
(conj entities (o-shape x y)) ;; This is effectively a no-op, results are not used.
(write-state [x y])) ;; returns the results of write-state,
;; ie the result of conj-ing [x y] onto the value in ref state
但是,我现在认为你的问题的根源是两个版本有不同的返回值。这是第一次返回的内容:
(defn add-shape
[x y entities]
(write-state [x y])
(conj entities (o-shape x y))) ;; returns the results of conj-ing the results of (o-shape x y)
;; onto the passed-in value of entities
TLDR:函数返回不同的值,您的程序可能只适用于您的第一个结果。