2016-04-28 43 views
1

我正在使用Quil與Clojure,並得到一個奇怪的錯誤。通過錯誤的參數數量,但我通過正確的金額

我得到的錯誤

Exception in :draw function: #error { 
:cause Wrong number of args (1) passed to: core/move-circle/fn--14896 
:via 

這裏是唯一的代碼,動圈存在

(defn bounce-back [c state] 
    (or (<= (:x c) 0) (<= (:y c) 0) (>= (:x c) (inc (:size state))) (>= (:y c) (inc (:size state)))) 
) 

(defn move-circle 
    "Moves a circle according to its speed and heading" 
    [c state] 
    (let [size (:size state) x (:x c) y (:y c) ux (atom 1) uy (atom 1) heading (atom (:heading c))] 
    (if (bounce-back c state) (swap! heading + q/PI) (swap! heading + 0)) 
     (swap! ux #(mod 500 (* (q/cos @heading) (:speed c)))) 
     (swap! uy #(mod 500 (* (q/sin @heading) (:speed c)))) 
     (println "X: " x "Y: " y) 
     (println "UX: " @ux "Y: " @uy) 
     (update-in (update-in (update-in c [:y] #(+ y @uy)) [:x] #(+ x @ux)) [:heading] #(if (= @heading (:heading c)) (:heading c) @heading)) 
) 
) 

(defn update-circles 
    "Moves each circle and returns updated vector of circles." 
    [circles state] 
    (println "Update Circles") 
    (map (fn [c] (move-circle c state)) circles)) 

這裏是堆棧跟蹤

quil-workflow 0.1.0-SNAPSHOT[stdout]: 
Update Circles 
quil-workflow 0.1.0-SNAPSHOT[stdout]: 
Exception in :draw function: #error { 
:cause Wrong number of args (1) passed to: core/move-circle/fn--14896 
:via 
[{:type clojure.lang.ArityException 
    :message Wrong number of args (1) passed to: core/move-circle/fn--14896 
    :at [clojure.lang.AFn throwArity AFn.java 429]}] 
:trace 
[[clojure.lang.AFn throwArity AFn.java 429] 
    [clojure.lang.AFn invoke AFn.java 32] 
    [clojure.lang.Atom swap Atom.java 37] 
    [clojure.core$swap_BANG_ invokeStatic core.clj 2260] 
    [clojure.core$swap_BANG_ invoke core.clj 2253] 
    [circles.core$move_circle invokeStatic nil 55] 
    [circles.core$move_circle invoke nil 55] 
    [circles.core$update_circles$fn__14907 invoke nil 68] 
    [clojure.core$map$fn__4785 invoke core.clj 2646] 
    [clojure.lang.LazySeq sval LazySeq.java 40] 
    [clojure.lang.LazySeq seq LazySeq.java 49] 
    [clojure.lang.RT seq RT.java 521] 
    [clojure.core$seq__4357 invokeStatic core.clj 137] 
    [clojure.core$map$fn__4785 invoke core.clj 2637] 
    [clojure.lang.LazySeq sval LazySeq.java 40] 
    [clojure.lang.LazySeq seq LazySeq.java 49] 
    [clojure.lang.RT seq RT.java 521] 
    [clojure.core$seq__4357 invokeStatic core.clj 137] 
    [clojure.core$dorun invokeStatic core.clj 3024] 
    [clojure.core$dorun invoke core.clj 3024] 
    [circles.core$draw_state invokeStatic nil 92] 
    [circles.core$draw_state invoke nil 92] 
    [clojure.lang.Var invoke Var.java 379] 
    [quil.middlewares.fun_mode$wrap_draw_update$quil_draw__6769 invoke fun_mode.cljc 16] 
    [quil.middlewares.safe_fns$wrap_fn$fn__114 invoke safe_fns.clj 9] 
    [quil.middlewares.bind_output$bind_output$iter__148__152$fn__153$fn__164 invoke bind_output.clj 21] 
    [quil.applet$_draw invoke applet.clj 220] 
    [quil.Applet draw nil -1] 
    [processing.core.PApplet handleDraw PApplet.java 2402] 
    [quil.Applet handleDraw nil -1] 
    [processing.awt.PSurfaceAWT$12 callDraw PSurfaceAWT.java 1527] 
    [processing.core.PSurfaceNone$AnimationThread run PSurfaceNone.java 316]]} 
stacktrace: clojure.lang.ArityException: Wrong number of args (1) passed to: core/move-circle/fn--14896 
at clojure.lang.AFn.throwArity (AFn.java:429) 
    clojure.lang.AFn.invoke (AFn.java:32) 
    clojure.lang.Atom.swap (Atom.java:37) 
    clojure.core$swap_BANG_.invokeStatic (core.clj:2260) 
    clojure.core$swap_BANG_.invoke (core.clj:2253) 
    circles.core$move_circle.invokeStatic (:55) 
    circles.core$move_circle.invoke (:55) 
    circles.core$update_circles$fn__14907.invoke (:68) 
    clojure.core$map$fn__4785.invoke (core.clj:2646) 
    clojure.lang.LazySeq.sval (LazySeq.java:40) 
    clojure.lang.LazySeq.seq (LazySeq.java:49) 
    clojure.lang.RT.seq (RT.java:521) 
    clojure.core$seq__4357.invokeStatic (core.clj:137) 
    clojure.core$map$fn__4785.invoke (core.clj:2637) 
    clojure.lang.LazySeq.sval (LazySeq.java:40) 
    clojure.lang.LazySeq.seq (LazySeq.java:49) 
    clojure.lang.RT.seq (RT.java:521) 
    clojure.core$seq__4357.invokeStatic (core.clj:137) 
    clojure.core$dorun.invokeStatic (core.clj:3024) 
    clojure.core$dorun.invoke (core.clj:3024) 
    circles.core$draw_state.invokeStatic (:92) 
    circles.core$draw_state.invoke (:92) 
    clojure.lang.Var.invoke (Var.java:379) 
    quil.middlewares.fun_mode$wrap_draw_update$quil_draw__6769.invoke (fun_mode.cljc:16) 
    quil.middlewares.safe_fns$wrap_fn$fn__114.invoke (safe_fns.clj:9) 
    quil.middlewares.bind_output$bind_output$iter__148__152$fn__153$fn__164.invoke (bind_output.clj:21) 
    quil.applet$_draw.invoke (applet.clj:220) 
    quil.Applet.draw (:-1) 
    processing.core.PApplet.handleDraw (PApplet.java:2402) 
    quil.Applet.handleDraw (:-1) 
    processing.awt.PSurfaceAWT$12.callDraw (PSurfaceAWT.java:1527) 
    processing.core.PSurfaceNone$AnimationThread.run (PSurfaceNone.java:316) 
+0

你打電話給移動圈怎麼樣? – jmargolisvt

+0

對不起,我想它沒有做一個填充複製粘貼。編輯我的主帖 –

回答

3

錯誤信息沒有按不要說你將錯誤的參數傳遞給移動圓圈,而是移動圓圈$ fn:a lambda移動圈內。在這種情況下,這是

#(mod 500 (* (q/cos @heading) (:speed c)) 

你傳遞這個0參數的函數作爲參數傳遞給swap!,但swap!一個參數調用其功能。

+0

我仍然得到相同的錯誤,當我將它改爲 '(swap!ux(fn [x](mod 500(*(q/sin @heading)(:spe​​ed c)))) )' –

+0

不,你得到一個非常相似的錯誤:行號不同,因爲你在下一行做出完全相同的錯誤!如果你修正*那*,你會得到另一個類似的錯誤,因爲你在調用'update-in'時又犯了同樣的錯誤*,它也需要一個參數而不是無的函數。 – amalloy