This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-13
Channels
- # beginners (78)
- # boot (27)
- # cider (13)
- # cljs-dev (41)
- # cljsrn (4)
- # clojure (216)
- # clojure-android (1)
- # clojure-conj (6)
- # clojure-greece (1)
- # clojure-italy (11)
- # clojure-russia (127)
- # clojure-spec (63)
- # clojure-uk (34)
- # clojurescript (68)
- # core-async (5)
- # cursive (5)
- # data-science (1)
- # datomic (4)
- # dirac (11)
- # editors (7)
- # events (1)
- # graphql (12)
- # hoplon (39)
- # jobs (1)
- # liberator (3)
- # lumo (101)
- # off-topic (14)
- # om (3)
- # onyx (3)
- # parinfer (14)
- # re-frame (10)
- # reagent (2)
- # remote-jobs (1)
- # ring-swagger (17)
- # sql (21)
- # untangled (38)
- # vim (3)
- # yada (23)
hey guys, quick question: what is the clojure/spec.alpha
project in github? is it an old version of clojure.spec
?
I think it's the new version
yes, the fact that the readme mentions nothing about what it is doesn't help tbh (or how to use it; you have to dig into the google group announcement instead)
is it possible to use spec to ensure that one spec'ed key in a map containing a number is larger than the value another spec'ed key?
starting with something like this:
(s/def :my.app/start int?)
(s/def :my.app/end int?)
(s/def :my.app/timer
(s/keys :req [:my.app/start :my.app/end]))
Yes, you can do something like
(s/def :my.app/timer
(s/and (s/keys :req [:my.app/start :my.app/end])
#(<= (:my.app/start %) (:my.app/end %))))
Yeah, the 2nd arg is a spec, which can be specs from the spec namespace, sets, or really any function that returns truthy/falsey, or any combination.
The docs say spec, spec-name, predicate or regex-op
this is probably a dumb question, but when exercising a spec with a custom function (such as the <= above), is clojure generating ints at random and then only filtering out results that pass the spec? or is it truly generating valid specs on the first try?
s/and
uses the first spec as a generator, and the following specs as filters
as far as I remember
If you want something more intelligent, you'd have to provide the generator yourself
https://groups.google.com/forum/#!msg/clojure/10dbF7w2IQo/ec37TzP5AQAJ <- @mattly, seems that the plan is to move back to a non-alpha namespace after
It is likely that 1.9 will release before spec is finalized (that is, 1.9 final will depend on clojure.spec.alpha). Being able to do so is the main reason we did the split.
can someone help me understand why this is producing a vector of vectors rather than a single collection of numbers?
(s/def :test/coll (s/coll-of number?))
(s/exercise :test/coll)
=> ([[-2.0 -1 0 -2.0 -2.0 1.0 0 0.5 0 0 -0.5 -2.0 0.5 -0.5] [-2.0 -1 0 -2.0 -2.0 1.0 0 0.5 0 0 -0.5 -2.0 0.5 -0.5]]
[[0 0 -3.0 -1 0 -1 -1 -0.75 -1 -1 0 -1 -2.0]...]
me too
does NaN pass number?
you probably already answered that for yourself…
(defn nan? [x]
(if (number? x)
(not (= (double x) (double x)))
true))
(fact "NaNs are true and numbers are false"
(nan? 0) => false
(nan? 1) => false
(nan? 3.4) => false
(nan? -7.0) => false
(nan? "yoplait") => true
(nan? "") => true
(nan? Float/NaN) => true
(nan? Double/NaN) => true
(= (nan? Float/NaN) (number? Float/NaN)) => true ;; this highlights that (nan?) is not a precise complement of (number?)
(= (nan? Double/NaN) (number? Double/NaN)) => true
)
I didn't; NaN is a pretty thorny case for generators, primarily because they don't equal themselves
otherwise I think it's appropriate for a number?
generator to generate them
joshkh: Float/NaN
and Double/NaN
are distinct floating point literals available in clojure. Sorry if I am late
Oops missed your reply sorry 😦
Double/POSITIVE_INFINITY
& Double/NEGATIVE_INFINITY
it's all good! your guidance steered me true. i just had to adjust for javascript which... against all odds... supports positive infinity 🙂
it's an instance of Double
read the docstring for s/exercise
it's not a coincidence that you have pairs of identical collections
@joshkh exercise generates values, and conforms them, then returns a collection of those pairs
you can also (gen/sample :test/coll) to just get the samples
that's the second time i've stared right past the docs today. time for a coffee. thanks guys.
or (map first (s/exercise :test/coll))
@mpenet I updated the spec.alpha readme a little
it is pushed
I was looking at core.specs.alpha :D mixed the two. I guess it might get a readme update as well there
oh, yeah. will do
certainly better than nothing! I meant to come back to those, just forgot to do so after the release.