This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-13
Channels
- # announcements (5)
- # babashka (35)
- # beginners (65)
- # braveandtrue (3)
- # calva (20)
- # cider (6)
- # clara (11)
- # cljs-dev (36)
- # cljsrn (64)
- # clojure (65)
- # clojure-europe (6)
- # clojure-germany (13)
- # clojure-italy (14)
- # clojure-nl (22)
- # clojure-spec (16)
- # clojure-sweden (6)
- # clojure-uk (81)
- # clojurescript (71)
- # conjure (120)
- # cursive (3)
- # datomic (10)
- # events (4)
- # figwheel (4)
- # figwheel-main (5)
- # fulcro (36)
- # ghostwheel (1)
- # graalvm (8)
- # helix (9)
- # jobs (4)
- # jobs-discuss (12)
- # kaocha (33)
- # leiningen (5)
- # luminus (1)
- # off-topic (24)
- # pathom (7)
- # rdf (4)
- # re-frame (3)
- # reagent (15)
- # reitit (11)
- # remote-jobs (1)
- # shadow-cljs (97)
- # slack-help (3)
- # spacemacs (23)
- # vim (15)
- # xtdb (35)
(s/def ::fact
(s/cat :var (s/? ::?symbol)
:type (s/or :simple symbol? :acc ::acc-vec)
:destruct (s/? vector?)
:exprs (s/* list?)))
(s/def ::fact-without-var
(s/cat :type (s/or :simple symbol? :acc ::acc-vec)
:destruct (s/? vector?)
:exprs (s/* list?)))
Is there a way to get rid of the repetition here without introducing more nesting and keywords in the conformed data?doesn't the first one include the second?
so, you can create a new spec that is an s/cat that just contains the common portions, then reference it in both ::fact specs
(s/def ::fact-without-var
(s/cat :type (s/or :simple symbol? :acc ::acc-vec)
:destruct (s/? vector?)
:exprs (s/* list?)))
(s/def ::fact
(s/cat :var (s/? ::?symbol)
:tail ::fact-without-var))
that does introduce nesting in the conformed data so is not everything you want
another way would be to restrict the bigger one
maybe something like
(s/def ::fact
(s/cat :var (s/? ::?symbol)
:type (s/or :simple symbol? :acc ::acc-vec)
:destruct (s/? vector?)
:exprs (s/* list?)))
(s/def ::fact-without-var
(s/& ::fact #(nil? (:var %))))
can't say I've done this before, might need to tweak that predicate more
& just lets you and arbitrary predicates into the regex spec