Skip to content

Instantly share code, notes, and snippets.

@bhb
Created August 31, 2017 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhb/de31b73133d6322158a3c0a5d47d67a2 to your computer and use it in GitHub Desktop.
Save bhb/de31b73133d6322158a3c0a5d47d67a2 to your computer and use it in GitHub Desktop.
`:clojure.spec.alpha/spec` is a function, whereas `:pred` is a symbol
If a predicate is passed to `explain-data` directly (to be used as a spec), then the `spec` value is not a symbol, but the function itself.
This makes it tricky to write a consistent printer - I'd like to be able to say "<value> did not match <predicate>" in a consistent way.
user=> *clojure-version*
{:major 1, :minor 9, :incremental 0, :qualifier "alpha19"}
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (::s/spec (s/explain-data string? 1))
#object[clojure.core$string_QMARK___4964 0x125290e5 "clojure.core$string_QMARK___4964@125290e5"]
user=> (type (::s/spec (s/explain-data string? 1)))
clojure.core$string_QMARK___4964
user=> (s/def :example/str string?)
:example/str
user=> (:pred (first (::s/problems (s/explain-data :example/str 1))))
clojure.core/string?
user=> (type (:pred (first (::s/problems (s/explain-data :example/str 1)))))
clojure.lang.Symbol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment