传递的参数数量错误,但是我传递了正确的数量

时间:2016-04-28 16:12:44

标签: java clojure quil

我正在使用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)

1 个答案:

答案 0 :(得分:3)

错误消息并未说明您将错误数量的参数传递给移动圈,而是移动圈$ fn:移动圈内的 lambda 。在这种情况下,那是

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

您将此0参数函数作为参数传递给swap!,但swap!使用一个参数调用其函数。