How to read clojure exceptions in REPL? -
many times when seek write function exception. normal. in java can find place , reason why exception occures in clojure exception texts create me crazy. there tips how read exceptions in clojure , how find in code exception happens , why?
for illustration take code:
(do (list?) (list? []) (list? '(1 2 3)) (list? (defn f [] (do ()))) (list? "a"))
when phone call function in repl
java.lang.illegalargumentexception: wrong number of args (0) passed to: core$list-qmark- (no_source_file:46)
which not help me much find problem in sec line. in little more complicated code give no information. (of course of study tells @ list? in there wrong number of arguments.) wrong seek write code in repl? how read exception mesages in repl? there way how improve info exceptions in repl?
acquire org.clojure/tools.trace
.
user=> (use 'clojure.tools.trace)
let's seek dotrace
(changed order create things more interesting):
user=> (dotrace [list?] #_=> (do #_=> (list? []) #_=> (list? '(1 2 3)) #_=> (list?) #_=> (list? (defn f [] (do ()))) #_=> (list? "a")) #_=> ) illegalstateexception can't dynamically bind non-dynamic var: clojure.core/list? clojure.lang.var.pushthreadbindings (var.java:353)
hmm...
user=> (.setdynamic #'list?) #'clojure.core/list?
let's seek again:
user=> (dotrace [list?] #_=> (do #_=> (list? []) #_=> (list? '(1 2 3)) #_=> (list?) #_=> (list? (defn f [] (do ()))) #_=> (list? "a"))) trace t1216: (list? []) trace t1216: => false trace t1217: (list? (1 2 3)) trace t1217: => true trace t1218: (list?) arityexception wrong number of args (0) passed to: core$list-qmark- clojure.lang.afn.throwarity (afn.java:437)
aha! made (list?)
before exception.
clojure
No comments:
Post a Comment