Fork me on GitHub

+1; by the way; I have nothing to contribute to that other than “I can explain a problem better than my consumers can read Clojure” 😄


how do I create an enum spec? Value that conforms that is in a given set?


(s/def ::set-spec #{:value1 :value2 :value3})


It's just the set itself.


yeah but oh… I got it… (gen/generate (s/gen (s/and #{:foo :boo})))


I was using s/exercise its output confused me


@ag I think (gen/generate (s/gen #{:foo :boo})) is equivalent


Out of curiosity: Is there a way to say "in this s/cat spec, please omit this item and this item from the map resulting from s/conform"? One example (s/def ::myspec (s/cat :first-operand number? :_ #{:plus :minus} :second-operand number?)) -> (s/conform ::myspec [15 :plus 10]]) -> {:first-operand 15 :second-operand 10} (with the :_ key indicating "please don't include this in the result")?


I'm asking because I'm parsing a small language with clojure.spec and there are some parts in the language that I don't care about later on. And the simpler the output of s/conform the better - in this case.

Alex Miller (Clojure team)15:09:00

there is no way to automatically omit syntactic elements like that, but you can use a conformer to get the same effect

Alex Miller (Clojure team)15:09:03

something like (s/conform (s/and ::myspec (s/conformer #(dissoc % :_)) [15 :plus 10]])

Alex Miller (Clojure team)15:09:04

you can put the conformer inside the spec too of course, just wrapping here as an example


That's pretty awesome.


I assume I can't have multiple :_s in an s/cat?

Alex Miller (Clojure team)15:09:04

it probably wouldn’t throw an error, but I haven’t tried it

Alex Miller (Clojure team)15:09:40

they’d probably all just override the prior as it parsed - you wouldn’t be able to unform that but doesn’t seem like you care about that anyways

Alex Miller (Clojure team)15:09:09

(`conformer` can also take an unform function to support both directions)


Yep, later :_s override earlier occurences in the resulting map.


Cool. I'm not sure I'm going to use this but it could make my life easier.


Is there an idiomatic way to define :args and :ret when defining a function without a separate fdef declaration? It would be easy to write a macro to do this, but is it considered bad practice?


(similar to schema’s s/defn)

Alex Miller (Clojure team)16:09:59

spec does not provide this (and does not intend to)

Alex Miller (Clojure team)16:09:06

but you’re welcome to do so :)


@alexmiller I’m curious why spec :args and :ret are not defined in defn like pre and postconditions?

Alex Miller (Clojure team)16:09:25

Rich talks about the notion of an independent registry at

Alex Miller (Clojure team)16:09:13

That is, we don't need to hang everything off vars (and there are downsides to doing so, that affect bytecode size and startup time)

Alex Miller (Clojure team)16:09:48

Also, from the purposes of API evolution, it is useful for the specs to be independent from the vars


Got it. Thanks for the explanation.


the “API evolution” sound interesting. I assume that’s yet to be announced?

Alex Miller (Clojure team)16:09:04

Rich talked about some of that on the Cognicast episode he did


when he was talking about Postel's Law and API versioning?

Alex Miller (Clojure team)16:09:40

But the idea is that if the specs are independent from the functions you can talk (programmatically) about whether one api subsumed another


that makes sense

Alex Miller (Clojure team)21:09:14

in particular, Rich did a big perf pass and improved times of most things


@alexmiller have you talked to or has rich mentioned anything by the way of the explainer concept we talked about yesterday? it'd be really nice to have something to pair with conformer to produce explanation data for custom conformers!