clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
pbrown 2021-03-19T21:48:07.006300Z

Hey there -- I really like this idea of closing specs at check-time in spec 2. Will there be (or is there already) a way to apply the same idea to sequential specs? Let's say I'm speccing hiccup as

(defmulti form-of first)
(defmethod form-of :default [_]
  (s/cat :tag keyword?
         :props (s/? map?)
         :children (s/* ::node)))
(s/def ::component (s/multi-spec form-of (fn [val _tag] val)))
(s/def ::node
       (s/or :component (s/and vector? ::component)
             :list (s/coll-of ::node
                              :kind (every-pred sequential?
                                                (complement vector?)))
             :atom (complement coll?)))
and define a bunch of components like
(defmethod form-of :script [_]
  (s/cat :tag #{:script}
         :props (s/? map?)
         :children (s/* string?)))
Could I later restrict ::component somehow to reject [:script ...] as part of the instruction to s/valid?? Or could my defmethods check a dynamic binding, say *illegal-tags*?