Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
Clojure does this.

Example:


$ clj -R:clj/next
Clojure 1.10.0-beta3
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (require '[clojure.spec.test.alpha :as st])
nil
user=> (defn foo [x] (inc x))
#'user/foo
user=> (s/fdef foo :args (s/cat :n int?))
user/foo
user=> (st/instrument)
[user/foo]
user=> (foo "A")
Evaluation error - invalid arguments to user/foo at (null:6).
"A" - failed: int? at: [:n]
user=> (pst)
ExceptionInfo Call to #'user/foo did not conform to spec. {:clojure.spec.alpha/problems [{:path [:n], :pred clojure.core/int?, :val "A", :via [], :in [0]}], :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x7bb6ab3a "clojure.spec.alpha$regex_spec_impl$reify__2509@7bb6ab3a"], :clojure.spec.alpha/value ("A"), :clojure.spec.alpha/fn user/foo, :clojure.spec.alpha/args ("A"), :clojure.spec.alpha/failure :instrument, :clojure.spec.test.alpha/caller {:file nil, :line 6, :var-scope user/eval143}}
    clojure.spec.test.alpha/spec-checking-fn/conform!--3024 (alpha.clj:132)
    clojure.spec.test.alpha/spec-checking-fn/fn--3026 (alpha.clj:140)
    user$eval143.invokeStatic (:6)
    user$eval143.invoke (:6)
    clojure.lang.Compiler.eval (Compiler.java:7172)
    clojure.lang.Compiler.eval (Compiler.java:7135)
    clojure.core/eval (core.clj:3206)
    clojure.core/eval (core.clj:3202)
    clojure.main/repl/read-eval-print--8898/fn--8901 (main.clj:309)
    clojure.main/repl/read-eval-print--8898 (main.clj:307)
    clojure.main/repl/fn--8907 (main.clj:332)
    clojure.main/repl (main.clj:332)
nil

2 Answers

0 votes
by

Comment made by: mfikes

Looking into this a little, this is non-trivial to implement given that it touches on stacktrace / exception handling that is specific to each REPL environment.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2946 (reported by mfikes)
...