This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-07
Channels
- # admin-announcements (2)
- # arachne (1)
- # bangalore-clj (2)
- # beginners (39)
- # boot (349)
- # cider (31)
- # clara (2)
- # cljs-dev (9)
- # cljsjs (67)
- # cljsrn (7)
- # clojure (300)
- # clojure-art (4)
- # clojure-greece (11)
- # clojure-hk (3)
- # clojure-israel (1)
- # clojure-italy (17)
- # clojure-japan (1)
- # clojure-russia (33)
- # clojure-sg (2)
- # clojure-spec (41)
- # clojure-uk (86)
- # clojurescript (123)
- # clojurex (3)
- # code-reviews (1)
- # component (6)
- # crypto (1)
- # cursive (36)
- # datomic (32)
- # devcards (3)
- # emacs (11)
- # events (3)
- # funcool (4)
- # luminus (10)
- # om (28)
- # onyx (88)
- # pedestal (2)
- # re-frame (84)
- # reagent (7)
- # ring-swagger (3)
- # specter (33)
- # sql (2)
- # vim (21)
+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” 😄
(s/def ::set-spec #{:value1 :value2 :value3})
It's just the set itself.
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.
there is no way to automatically omit syntactic elements like that, but you can use a conformer to get the same effect
something like (s/conform (s/and ::myspec (s/conformer #(dissoc % :_)) [15 :plus 10]])
you can put the conformer inside the spec too of course, just wrapping here as an example
it probably wouldn’t throw an error, but I haven’t tried it
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
(`conformer` can also take an unform function to support both directions)
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?
spec does not provide this (and does not intend to)
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?
Several reasons
Rich talks about the notion of an independent registry at http://clojure.org/about/spec
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)
Also, from the purposes of API evolution, it is useful for the specs to be independent from the vars
Rich talked about some of that on the Cognicast episode he did
But the idea is that if the specs are independent from the functions you can talk (programmatically) about whether one api subsumed another
1.9.0-alpha12 is out, mostly spec related things https://groups.google.com/forum/#!topic/clojure/lQ5beZB6QYE
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!