This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-20
Channels
- # bangalore-clj (1)
- # beginners (145)
- # boot (8)
- # braid-chat (2)
- # capetown (2)
- # cider (27)
- # cljs-dev (232)
- # cljsrn (30)
- # clojure (223)
- # clojure-boston (1)
- # clojure-dusseldorf (2)
- # clojure-greece (1)
- # clojure-italy (21)
- # clojure-russia (16)
- # clojure-sanfrancisco (13)
- # clojure-spec (33)
- # clojure-uk (56)
- # clojurescript (165)
- # core-async (16)
- # core-logic (5)
- # cursive (14)
- # data-science (2)
- # datavis (2)
- # datomic (49)
- # duct (15)
- # editors (5)
- # emacs (6)
- # fulcro (11)
- # graphql (11)
- # hoplon (8)
- # jobs (4)
- # jobs-discuss (82)
- # jobs-rus (7)
- # leiningen (4)
- # luminus (5)
- # off-topic (90)
- # om (7)
- # om-next (1)
- # parinfer (67)
- # pedestal (34)
- # portkey (46)
- # re-frame (12)
- # reagent (4)
- # reitit (3)
- # remote-jobs (1)
- # ring-swagger (8)
- # shadow-cljs (13)
- # spacemacs (18)
- # specter (6)
- # sql (5)
- # tools-deps (4)
- # unrepl (40)
- # yada (26)
This feature still requires a lot of work, but soon(ish), Expound will be able to provide examples of valid clojure code https://gist.github.com/bhb/f637ef589ef3ac3d2ca5a883fafc2c12
However, this adds a dependency on test.check to use expound at dev time. Would you prefer to have this be a hard dependency OR would you prefer expound to disable this feature if you don’t have test.check available?
@mcama200 spec/keys
is a macro so it takes literal code forms, not variables.
What you can do instead is to use the literal vector in s/keys
and then call s/form
(I think?) on the spec itself and walk that to get the list of required keys back out of a spec definition.
@alexisvincent The short answer is: specs are currently pretty static so you have to have multiple specs -- or specify that :card/cvv
is :opt
in the base spec and then wrap it in another spec that uses s/and
and a predicate that "requires" that key be present.
(s/def :card/full-details (s/and :card/details #(contains? % :card/cvv)))
something like that (untested)I guess spec could eat its own dog food?
boot.user=> (s/fdef foo (s/cat :a1 string?))
java.lang.IllegalArgumentException: No value supplied for key: (s/cat :a1 string?)
clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: No value supplied for key: (s/cat :a1 string?), compiling:(null:1:1)
Actually it can’t, unless you enjoy infinite recursion
been there done that: my personal favorite is (s/def foo any?) or (s/fdef ::foo :args (s/cat))
@seancorfield Thanks for the answer, the s/and
is neat, and will help reduce branching factor, but I don’t think it’s a long term behaviour. I can use functions that return specs, but loose out on spec’s repository. Do you know if dynamism will be added to named specs in the future, or if it even needs to be?
I have the current spec (simplified):
(s/fdef widget
:args
(s/cat :opts
(s/keys
:req-un [::title
::content]
:opt-un [
::init-collapsed?
::fixed?])))
How do I say init-collapsed?
and fixed?
are mutually exclusive?if you say the widget must be fixed, init-collapsed? can not be true, because the widget won’t be visible at all that way
I imagine a multispec could do it too, but that's prolly too much complexity for such as simple check
java.util.concurrent.ExecutionException: clojure.lang.ExceptionInfo: Couldn't satisfy such-that predicate after 100 tries. {}
agreed :)
unfortunately, the current linkage between spec and test.check prevents good error reporting on where this is happening. there are plans to make this better, but it requires changes in both projects.
@alexmiller I'm curious how what you just described relates to an earlier comment that spec can't enscricten its version requirements of test.check
enscricten = ?
make more scrict
and scrict = ?
opposite of pecmissive
@alexisvincent define all your fields’ specs, and then have several s/keys specs for different combinations of those fields. Then you might want to have the card spec, which is s/or around those s/keys