This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-01
Channels
- # announcements (1)
- # babashka (1)
- # beginners (45)
- # business (3)
- # calva (43)
- # clojure (57)
- # clojure-spec (6)
- # clojure-uk (4)
- # clojured (8)
- # clojurescript (14)
- # cryogen (3)
- # datomic (2)
- # emacs (36)
- # fulcro (20)
- # garden (2)
- # jobs (2)
- # lumo (3)
- # meander (9)
- # off-topic (1)
- # other-lisps (1)
- # reagent (13)
- # shadow-cljs (25)
- # spacemacs (20)
- # tools-deps (11)
In spec2, how would I use a set spec to match against a symbol that happens to be the name of a macro?
> (s/def ::is-foo #{foo})
:expound.alpha2.core-test/is-foo
> (s/form ::is-foo)
#{foo}
> (s/explain ::is-foo 'foo)
Success!
nil
> (s/def ::is-or #{or})
:expound.alpha2.core-test/is-or
> (s/form ::is-or)
#{clojure.core/or}
> (s/explain ::is-or 'or)
or - failed: #{clojure.core/or} spec: :expound.alpha2.core-test/is-or
nil
Or should I avoid using set specs in this case?there is actually a known issue around sets of symbols (kind of a collision with symbol as function reference, which need qualification)
a workaround for the moment is (s/register ::is-or (s/resolve-spec #{'or}))
👍 4
4
Perhaps just a different view on the same underlying issue, but it looks like spec2 is using clojure.core/and
instead of the and
symbol for combining specs in :req
?
> (s/def :keys-spec/name string?)
> (s/def :keys-spec/age int?)
> (s/def :key-spec/state string?)
> (s/def :key-spec/city string?)
> (s/def :key-spec/zip pos-int?)
> (s/def :keys-spec/user2 (s/keys :req [(and :keys-spec/name
:keys-spec/age)]
:req-un [(or
:key-spec/zip
(and
:key-spec/state
:key-spec/city))]))
> (s/form :keys-spec/user2)
(clojure.alpha.spec/keys :req [(clojure.core/and :keys-spec/name :keys-spec/age)] :req-un [(clojure.core/or :key-spec/zip (clojure.core/and :key-spec/state :key-spec/city))])