Spec metaprogramming is definitely in the intended use case for clojure.spec.
We have not yet released (but wrote and intended) specifications for special forms. With their help, you can combine the specification itself and return a data structure representing the specification that can be used (for example), capture the required keys from the map specification.
According to the specification :: spec might look something like this:
user=> (s/def ::name string?) :user/name user=> (s/def ::m (s/keys :req [::name])) :user/m user=> (s/conform ::spec (s/form ::m)) [:form {:s clojure.spec/keys, :args {:req [[:key :user/name]]}}]
Then you can snatch a set of keys from this structure.
Alex miller
source share