我无意中放置了 nth
的参数,并出现了以下错误和堆栈跟踪
Show: Project-Only All
Hide: Clojure Java REPL Tooling Duplicates (0 frames hidden)
2. Unhandled clojure.lang.Compiler$CompilerException
Error compiling NO_SOURCE_FILE at (79:3)
#:clojure.error{:phase :execution,
:line 79,
:column 3,
:source "NO_SOURCE_FILE"}
Compiler.java: 3719 clojure.lang.Compiler$InvokeExpr/eval
Compiler.java: 457 clojure.lang.Compiler$DefExpr/eval
Compiler.java: 7199 clojure.lang.Compiler/eval
Compiler.java: 7149 clojure.lang.Compiler/eval
core.clj: 3215 clojure.core/eval
core.clj: 3211 clojure.core/eval
interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 667 clojure.core/apply
core.clj: 1990 clojure.core/with-bindings*
core.clj: 1990 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn
main.clj: 437 clojure.main/repl/read-eval-print/fn
main.clj: 437 clojure.main/repl/read-eval-print
main.clj: 458 clojure.main/repl/fn
main.clj: 458 clojure.main/repl
main.clj: 368 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 84 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 56 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 152 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
AFn.java: 22 clojure.lang.AFn/run
session.clj: 202 nrepl.middleware.session/session-exec/main-loop/fn
session.clj: 201 nrepl.middleware.session/session-exec/main-loop
AFn.java: 22 clojure.lang.AFn/run
Thread.java: 829 java.lang.Thread/run
1. Caused by java.lang.ClassCastException
class clojure.lang.PersistentVector cannot be cast to class
java.lang.Number (clojure.lang.PersistentVector is in unnamed module of
loader 'app'; java.lang.Number is in module java.base of loader
'bootstrap')
REPL: 82 advent-of-clerk.year-2023.day-04/fn
REPL: 79 advent-of-clerk.year-2023.day-04/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
Compiler.java: 3714 clojure.lang.Compiler$InvokeExpr/eval
Compiler.java: 457 clojure.lang.Compiler$DefExpr/eval
Compiler.java: 7199 clojure.lang.Compiler/eval
Compiler.java: 7149 clojure.lang.Compiler/eval
core.clj: 3215 clojure.core/eval
core.clj: 3211 clojure.core/eval
interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 667 clojure.core/apply
core.clj: 1990 clojure.core/with-bindings*
core.clj: 1990 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn
main.clj: 437 clojure.main/repl/read-eval-print/fn
main.clj: 437 clojure.main/repl/read-eval-print
main.clj: 458 clojure.main/repl/fn
main.clj: 458 clojure.main/repl
main.clj: 368 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 84 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 56 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 152 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
AFn.java: 22 clojure.lang.AFn/run
session.clj: 202 nrepl.middleware.session/session-exec/main-loop/fn
session.clj: 201 nrepl.middleware.session/session-exec/main-loop
AFn.java: 22 clojure.lang.AFn/run
Thread.java: 829 java.lang.Thread/run
由于我同时更改了几个东西,导致很难找到问题。最终我意识到我已经放置了 nth
的集合和索引参数,但堆栈跟踪并没有帮助我意识到这一点:没有关于调用 nth
的提及,行号也没有指向有问题的那一行。
这里的完整示例代码: https://github.com/a1exsh/advent-of-clerk/blob/cddd42fcd60da2efcda37f222666328cd37fb616/src/advent_of_clerk/year_2023/day_04.clj#L84(这是正确的代码 — 要获得错误,请像这样交换参数:(nth i untouched)
)
我在用 CIDER(Emacs)中的 C-x C-e
评估单个循环形式的环境中遇到了这个问题。
当然,它可以在 REPL 中轻松重现,就像这样
user> (nth 0 [])
Execution error (ClassCastException) at user/eval22783 (REPL:42).
class clojure.lang.PersistentVector cannot be cast to class java.lang.Number (clojure.lang.PersistentVector is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')