Metaprogramming with clojure.spec values?

I tried clojure.spec, and one idea that I have for using it is to create a user interface for editing the map instance that I specify. For example, it can generate a web form with a datepicker field for a key that is listed as a date of this kind.

There is a get-spec method in the library, but there seem to be no functions that work with specification-as-values ​​as I need. Is there a way to do such things as take a card specification and return the required keys for that card as a vector? Is this metaprogramming with specifications beyond the intended use case of clojure.spec?

+7
clojure
source share
1 answer

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.

+7
source share

All Articles