This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-29
Channels
- # aleph (4)
- # architecture (12)
- # bangalore-clj (1)
- # beginners (87)
- # boot (3)
- # cider (19)
- # cljs-dev (84)
- # clojars (10)
- # clojure (79)
- # clojure-italy (7)
- # clojure-nl (19)
- # clojure-russia (10)
- # clojure-spec (9)
- # clojure-uk (55)
- # clojurescript (64)
- # core-async (7)
- # core-typed (4)
- # cursive (7)
- # data-science (2)
- # datomic (8)
- # devcards (6)
- # docs (1)
- # duct (5)
- # fulcro (117)
- # graphql (1)
- # instaparse (1)
- # leiningen (13)
- # lumo (103)
- # nyc (3)
- # off-topic (54)
- # om (9)
- # onyx (1)
- # pedestal (6)
- # planck (3)
- # portkey (7)
- # re-frame (26)
- # reagent (20)
- # ring-swagger (14)
- # shadow-cljs (164)
- # sql (11)
- # tools-deps (25)
- # yada (1)
I'm finding myself having to duplicate spec definitions in order to override generators and control the number of generated values. e.g.
(s/def ::name string?)
(s/def ::a (s/coll-of ::name))
(s/def ::b (s/keys :req-un [::a]))
(s/def ::c (s/keys :req-un [::a
::b]))
;; only generate a single element for ::a
(gen/generate (s/gen ::c {::a #(s/gen (s/coll-of ::name :min-count 1 :max-count 1))}))
(s/def ::select
(s/cat :plan-name #{'select}
:thing-to-select #{"SCV" "SupplyDepot"}
:at-least (s/cat :at-least-kw #{:at-least}
:at-least-number (s/int-in 1 50))
:and-do-form (s/? (s/cat :and-do-kw #{:and-do}
:additional-do ::select))))
(gen/sample (s/gen ::select) 1)
Why does this stackoverflow? I'd expect the recursive spec to hit a "0 arity branch" of the s/? before it runs out of stackI notice https://clojuredocs.org/clojure.spec.alpha/*recursion-limit* doesn't mention s/? so maybe it's not intended to be used recursively.
Ended up accepting I can't generate it, but still validate which will be enough for now.
(s/def ::select
(s/cat :plan-name #{'select}
:thing-to-select #{"SCV" "SupplyDepot"}
:at-least (s/cat :at-least-kw #{:at-least}
:at-least-number (s/int-in 1 50))
:and-do-form (s/with-gen (s/? (s/cat :and-do-kw #{:and-do}
:additional-do (s/spec (s/and list?
::select))))
#(gen/return ()))))
@bbss https://gist.github.com/bhauman/2dca87815dfd92b3ff596bdc1e56c964#file-compiler-options-schema-clj-L30
@victor.cleja you're saying a duplicate key is the issue?