Clojure就这样做。
示例
$ 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")
评估错误 - user/foo的无效参数在(null:6)。
"A" - 失败:int? 在: [:n]
user=> (pst)
ExceptionInfo 调用'#$user/foo'没有符合规范。{: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.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