This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-07
Channels
- # aleph (15)
- # beginners (18)
- # boot (18)
- # business (1)
- # cider (11)
- # cljs-dev (13)
- # cljsrn (19)
- # clojure (14)
- # clojure-austin (8)
- # clojure-dusseldorf (1)
- # clojure-finland (1)
- # clojure-greece (118)
- # clojure-poland (3)
- # clojure-russia (46)
- # clojure-spec (65)
- # clojure-uk (18)
- # clojurebridge (3)
- # clojurescript (16)
- # cloverage (7)
- # core-async (8)
- # cursive (74)
- # datomic (28)
- # editors (3)
- # emacs (3)
- # ethereum (5)
- # hoplon (19)
- # jobs-rus (18)
- # lein-figwheel (1)
- # off-topic (2)
- # om (107)
- # om-next (4)
- # onyx (23)
- # pedestal (23)
- # proton (3)
- # protorepl (1)
- # re-frame (108)
- # reagent (10)
- # ring-swagger (15)
- # spacemacs (2)
- # specter (11)
- # testing (7)
- # untangled (79)
- # vim (4)
- # yada (53)
Hello folks! I know how to spec a map with keys which I don't care the values of: (s/map-of #{:mid :seq} any?)
thanks to Alex, but is there a way standard pred to say "any non-nil value" or I must create my own predicate?
I tried (complement nil?)
but then the generator fails
@richiardiandrea probably some?
oh right, let me try
boot.user=> (s/def ::some some?)
:boot.user/some
boot.user=> (s/exercise ::some)
([{} {}] [{} {}] [(()) (())] [{([[]]) ([])} {([[]]) ([])}] [(-1/2 false) (-1/2 false)] [{{{{{} (-1.5)} ([\=])} []} [{}]} {{{{{} (-1.5)} ([\=])} []} [{}]}] [([:N4oa:*I+-:0:+c8_68:!!-6L]) ([:N4oa:*I+-:0:+c8_68:!!-6L])] [[[([true])]] [[([true])]]] [{} {}] [[()] [()]])
boot.user=>
yes it looks like that's what I was looking for thanks a lot @bfabry !
Looks like some?
always generates a collection tho’?
@richiardiandrea what about (s/and any? (complement nil?))
? That generates regular values that aren’t nil…
boot.user=> (s/exercise (s/and any? (complement nil?)))
([{} {}] [[] []] [[] []] [([false]) ([false])] [[()] [()]] [[] []] [{[[:Q5B+B:-vS7!+_2a:14s+?:Wd:?:E3+cY7:7q9n_V:+T*_] [L?lQDc.poz2z._rRq+9*Le._?.o.Pq!San9?!.uP36/y?+-i_]] {[] {}}} {[[:Q5B+B:-vS7!+_2a:14s+?:Wd:?:E3+cY7:7q9n_V:+T*_] [L?lQDc.poz2z._rRq+9*Le._?.o.Pq!San9?!.uP36/y?+-i_]] {[] {}}}] [{[] ()} {[] ()}] [[:AE+4CW!863.Rt_??z4!.ob*6.*M.J*+7!.?Wpz.RH?.k+L-L?-2_8.Dz_5E3zaY.!2GNEsM/N51M0Sn7 6 5] [:AE+4CW!863.Rt_??z4!.ob*6.*M.J*+7!.?Wpz.RH?.k+L-L?-2_8.Dz_5E3zaY.!2GNEsM/N51M0Sn7 6 5]] [[{[3 \s] [true], (s) (1/6)} {() (:?tLe9B2-66t.--s6+?8E*.*GVek-7!Y.++5BT3TQ6.x0Al3z.*7sAkrq8.*h9.a+P+.qz6?6?/KT-4!m+_4D -8), {\t v-Y+u+D+vk-.K?XwW-8?1?.+!529+.DaEb.erp7.hl?+??ma+t.-ZiN+y+.VC63aicOOe7.!226W+RFO.e1*??7/-q*.} {-5/3 \?}}] [{[3 \s] [true], (s) (1/6)} {() (:?tLe9B2-66t.--s6+?8E*.*GVek-7!Y.++5BT3TQ6.x0Al3z.*7sAkrq8.*h9.a+P+.qz6?6?/KT-4!m+_4D -8), {\t v-Y+u+D+vk-.K?XwW-8?1?.+!529+.DaEb.erp7.hl?+??ma+t.-ZiN+y+.VC63aicOOe7.!226W+RFO.e1*??7/-q*.} {-5/3 \?}}]])
Hmm, looking at those, most seem to be collections too…?
something weird going on there https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec/gen.clj#L133
Ah, I think it’s down to how any?
generates stuff...
there's no reason some? should be only collections, and I think that behaviour might be common
Looks like any?
generates nil
or a collection…
boot.user=> (->> (s/exercise any? 100) (map second) (remove coll?))
(nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil)
10,000 iterations don’t produce anything that isn’t nil
or a collection:
boot.user=> (->> (s/exercise any? 10000) (map second) (remove coll?) (remove nil?))
()
(dang, I love that you can do stuff like that so easily in the REPL!)
seems like the behaviour is inherited from clojure.test.check.generators/any-printable
yuuup
boot.user=> (remove coll? (remove nil? (repeatedly 1000 #(clojure.test.check.generators/generate clojure.test.check.generators/any-printable))))
()
That probably needs … enhancing ...
For generating maps only I was thinking of using an s/and
but for a first approximation of this spec some?
is perfect
That is good investigation though
Hello. ring-spec had just released. Imagine that library was named not "ring", but "com.stuartsierra.ring". For example, https://gist.github.com/prepor/c9a3ac1c5746146671b55631a543a6e4#file-spec-clj-L107. There are a lot of noise, aren't it?
i’ve never understood reverse domain name packages
i get the rationale, but it almost never pans out in practice. company names suffice, i find
(require '[clojure.spec :as s])
(create-ns 'com.this.looks.really.inconvenient)
(alias 'inco 'com.this.looks.really.inconvenient)
(s/def ::inco/bar int?)
=> :com.this.looks.really.inconvenient/bar
(s/valid? ::inco/bar 1)
=> true
(s/valid? :com.this.looks.really.inconvenient/bar 1)
=> true
> i’ve never understood reverse domain name packages this is the only way to guarantee name clashes absence
I’m amazed spec can parse the last case:
(s/def ::rhs (s/cat :lo (s/? symbol?)
:r (s/? (s/alt :rsh (s/cat :op #(= % 'RSHIFT)
:ro int?)
:or (s/cat :op #(= % 'OR)
:ro symbol?)
:not (s/cat :op #(= % 'NOT)
:ro symbol?)
))))
(s/conform ::rhs '[bn RSHIFT 2])
(s/conform ::rhs '[cj OR cp])
(s/conform ::rhs '[lx])
(s/conform ::rhs '[NOT ax])
I expected this not to work because NOT is also a symbol and that none other alt matches the restIs there a conform variant that throws like s/assert but returns the conformed value?
No but it's easy to make one
@prepor should work fine with aot
@seancorfield: if you filed a ticket on that any? some? generator business I would take a look at it. I keep forgetting to do so
@alexmiller ok, thank you
@lvh my current spec:
(s/def ::val (s/alt :name symbol? :value int?))
(s/def ::binary-operator #(#{'LSHIFT 'RSHIFT 'AND 'OR} %))
(s/def ::binary-expression (s/cat
:left-operand ::val
:operator ::binary-operator
:right-operand ::val))
(s/def ::not (s/cat :not #(= % 'NOT) :operand ::val))
(s/def ::lhs (s/alt :simple-value ::val
:binary-expression
::binary-expression
:not ::not))
(s/def ::rhs symbol?)
(s/def ::expr (s/cat :lhs ::lhs :arrow #(= % '->) :rhs ::rhs))
borkdude It’s pretty cool. I’m currently generating specs for swagger from the swagger json-schema definition, which I then use the generate swagger instances, from which I then generate instances of that swagger schema, which I then validate against the original swagger
It works. How do I get s/cat to generate vectors instead of whatever it generates now?
(gen/not-empty
(gen/fmap
(fn [s] (str/replace s #"[A-Z0-9]" ""))
gen/string-alphanumeric))
Thanks! I needed symbols of one or two character, so I got this now:
(s/with-gen symbol?
#(gen/fmap (fn [[i j]]
(symbol (string/lower-case (str i j))))
(gen/tuple (gen/char-alpha) (gen/char-alpha))))
Should work with :kind
, no?
(s/exercise (s/coll-of (s/cat :a nat-int? :b string?) :kind vector?))
@alexmiller https://clojurians.slack.com/archives/clojure-spec/p1475843093004536 http://dev.clojure.org/jira/browse/CLJ-2036
@seancorfield @alexmiller it actually seems like there's already a ticket on test.check http://dev.clojure.org/jira/browse/TCHECK-111
Thanks @bfabry — cross-linked