gpt4 book ai didi

java - 传递的 args 数量错误,但我传递了正确的数量

转载 作者:行者123 更新时间:2023-11-29 04:46:29 24 4
gpt4 key购买 nike

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

最佳答案

错误消息并不是说您将错误数量的参数传递给 move-circle,而是传递给 move-circle$fn:一个 lambda inside move-circle。在这种情况下,就是

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

您将这个 0 参数函数作为参数传递给 swap!,但是 swap! 使用一个参数调用它的函数。

关于java - 传递的 args 数量错误,但我传递了正确的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36920109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com