This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-27
Channels
- # adventofcode (3)
- # aws (1)
- # beginners (79)
- # boot-dev (1)
- # clara (50)
- # cljs-dev (7)
- # clojure (60)
- # clojure-austin (1)
- # clojure-germany (1)
- # clojure-greece (1)
- # clojure-russia (3)
- # clojure-spec (43)
- # clojure-uk (1)
- # clojurescript (76)
- # data-science (1)
- # datomic (26)
- # docs (2)
- # emacs (7)
- # fulcro (10)
- # hoplon (1)
- # instaparse (1)
- # lumo (3)
- # off-topic (16)
- # om (3)
- # onyx (2)
- # re-frame (3)
- # reagent (24)
- # ring-swagger (10)
- # shadow-cljs (15)
- # spacemacs (1)
- # sql (16)
- # uncomplicate (12)
- # unrepl (47)
I'm trying to work out what is happening with the following snippet, I think I must be misunderstanding how s/cat
works:
It makes no sense to me that it would be matching the first vector element on ::bound
, so I'm not sure how that's the spec it's failing.
@shdzzl I had issues wrapping my head around s/cat also, it kinda explodes the argument, is the best way I can describe it
I'm not sure I follow, it explodes which argument? I visualize it as kind of zipping predicates to a sequence, so my s/cat
example should match any seq of length three and check the first element against ::needs
, the second against ::bound
and the third against ::body
. What am I missing?
try (s/and vector? (s/cat .....))
Loading up a repl, one sec
@shdzzl well to start with your :needs spec fails
thats the real issue
(s/def ::needs (s/coll-of symbol?))
boot.user=> (s/explain (s/cat :needs ::needs :bound ::bound :body ::body) [['a 'b] {} '(+ a b)])
Success!
Uhuh, that does fix it. ::needs
wasn't failing when tested on it's own. Is there some flattening or something going on? I'm going to have read over s/*
again. Thanks a ton.
@shdzzl thats what s/cat is doing (s/cat :needs (s/* symbol?))
is different than when you move that into it’s own spec
rule of thumb for (s/cat)
build it up one arg at a time
otherwise it’s hard to figure out where it fails
While I'm here, I had another question. Is it possible/advisable to spec constructors (`MyRecord.` for example)?
It touches on it in the spec guide, but I was curious if someone had tried it with fdef
or similar.
user> (time (stest/check `a-symbol))
"Elapsed time: 2.153437 msecs"
does anyone have an explanation for why the above completes almost instantly but my repl does hang during the 10s of seconds that it actually takes to check the symbol in question?@johanatan what does that code print?
which code? it just prints the elapsed time line, then hangs until the check actually completes
and what does it return when it completes?
let me check. didn't wait for it to complete before because i was trying to debug why a loop/recur was spinning constantly instead of waiting for check
to complete
@tbaldridge it returned the typical map result from check
({:spec #object[clojure.spec.alpha$fspec_impl$reify__2451 0x6d92492f "[email protected]"], :clojure.spec.test.check/ret {:result true, :num-tests 1000, :seed 1514353342056}, :sym my-namespace/a-symbol})
interesting
So one last thing to try:
(do (time (stest/check
a-symbol)) nil)`
bleh you get the point, wrap it in a do, nil. that will remove any questions about REPL printing taking a long time
which is normally what it is in cases like this
hmm, that actually returned immediately like before but also gave me back control at the REPL prompt (i'm assuming the check
is happening in the bkg and i do have a process called main
doing a lot of CPU work in my procmon)
[i think main is the cider repl server if i'm not mistaken-- last time i killed it, cider immediately printed out a bunch of stuff indicating unhappiness lol]
[i suppose the result wasn't being dropped on the floor previously because the repl itself was waiting for the value to be returned so that it could print it]
@shdzzl sorry I havn’t tried that one