Fork me on GitHub
#clojure-spec
<
2016-09-07
>
lvh00:09:44

+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” 😄

ag01:09:35

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

sparkofreason01:09:03

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

sparkofreason01:09:12

It's just the set itself.

ag01:09:59

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

ag01:09:35

I was using s/exercise its output confused me

bbrinck02:09:24

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

jannis15:09:53

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")?

jannis15:09:12

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

jannis15:09:10

That's pretty awesome.

jannis15:09:55

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)

jannis15:09:37

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

jannis15:09:18

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

joshg16:09:29

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?

joshg16:09:21

(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 :)

joshg16:09:10

@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 http://clojure.org/about/spec

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

joshg16:09:45

Got it. Thanks for the explanation.

joshg16:09:41

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

joshg16:09:06

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

joshg16:09:28

that makes sense

Alex Miller (Clojure team)21:09:14

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

noprompt22:09:03

@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!