This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-06
Channels
- # adventofcode (1)
- # aleph (9)
- # announcements (22)
- # beginners (59)
- # boot (8)
- # calva (1)
- # cljdoc (7)
- # cljs-dev (10)
- # cljsrn (9)
- # clojars (10)
- # clojure (23)
- # clojure-dev (6)
- # clojure-europe (3)
- # clojure-italy (26)
- # clojure-nl (3)
- # clojure-seattle (1)
- # clojure-spec (46)
- # clojure-uk (85)
- # clojurescript (97)
- # core-async (13)
- # cursive (3)
- # data-science (10)
- # datomic (156)
- # duct (34)
- # emacs (37)
- # figwheel (3)
- # figwheel-main (9)
- # fulcro (59)
- # hyperfiddle (4)
- # immutant (1)
- # jackdaw (3)
- # jobs (1)
- # off-topic (112)
- # parinfer (1)
- # qlkit (2)
- # re-frame (1)
- # reagent (35)
- # ring-swagger (2)
- # shadow-cljs (104)
- # spacemacs (9)
- # speculative (12)
- # tools-deps (30)
- # yada (10)
So this is a spec error I ran into today and Im here thinking there must be a better way to get to the root of the problem
(defn- feature-dispatch [[k v]] k)
it’s probably the destructuring of the first arg, maybe a keyword is being passed as the first arg
^ I was able to solve this the problem was
(spec/explain-data ::feature-gate feature)
when I needed
(spec/explain-data ::feature-gate [feature])
@alexmiller I updated this comment just now: https://github.com/borkdude/speculative/issues/124#issuecomment-460944994
@alexmiller do you plan to support this for spec-alpha2 as well? https://dev.clojure.org/jira/browse/CLJ-2060 I noticed it does not yet work in CLJS.
should work, haven’t looked at why yet, but wasn’t intentionally broken
FYI, I just ran out entire test suite against the latest spec2 and there's just one failure (for s/valid?
on a large data structure for a very complex, nested spec) -- which was the unexplained failure I had before. The generator problems I mentioned before are fixed by the latest work.
@alexmiller What in spec (or spec2) causes this predicate to be used? (or (nil? %) (sequential? %))
(it's not in our code so I assume it's what underlies s/cat
or something?)
I think that’s checked for all regex specs
I assume you see that fail?
I've tracked it down a bit further...
(def s [ ... sequence of hash maps ...])
(count s) ;;=> 6
(s/explain ::ba-decline (take 3 s)) ;;=> Success!
(s/explain ::ba-decline (drop 3 s)) ;;=> Success!
(s/explain (s/cat :one ::ba-decline :two ::ba-decline) s)
;; fails, claiming that the first element of s does not satify: (or (nil? %) (sequential? %)) in: [0] at: [:one]
(this works with spec1)
Am I missing something obvious about combining regex specs?
The ::ba-decline
spec is an s/cat
of three items.
I'll see if I can create a minimal example that fails, based on this (unfortunately there are a lot of complex specs behind this).
(s/def ::x string?)
(s/def ::y int?)
(s/def ::z keyword?)
(s/def ::a (s/keys :req-un [::x]))
(s/def ::b (s/keys :req-un [::y]))
(s/def ::c (s/keys :req-un [::z]))
(s/def ::abc (s/cat :a ::a :b ::b :c ::c))
(def a {:x "x"})
(def b {:y 42})
(def c {:z :bar})
(s/explain ::abc [a b c])
(s/explain (s/cat :one ::abc :two ::abc) [a b c a b c])
works on spec1, fails on spec2on spec2 {:x "x"} - failed: (or (nil? %) (sequential? %)) in: [0] at: [:one]
user=> (s/explain (s/cat :one ::abc :two ::abc) [[a b c] [a b c]])
Success!
certainly is suspicious :)It's almost like regex specs don't unroll anymore! :rolling_on_the_floor_laughing:
I may have actually introduced that by introducing the delayed resolution of aliased specs
basically regex specs in the registry are shielded by the keyword (which is not a regex spec), so the code doesn’t believe they can be combined
so this may fight with the last changes - I can’t remember now if that was from forward references or from something about gens?
This was broken before you fixed either of those I believe. Certainly broken before the gensub fix.
well good to know then :)
Although, with a quick clj -Sdeps ...
it's enough to test that repro case against any version of spec2 🙂

I’ll take a look, seems buggy to me
There is a lot gnarly code in that form/object transition. I could easily have broken something subtle
Thanks for the repro
I was lucky that the first simple repro I tried still broke 🙂
Hey, that’s a good sign
At this point, it really is a pretty minimal set of changes in our code to go from spec1 to spec2. It's frustrating that we can no longer use comp
and partial
to construct predicates and have to resort to #(..)
or (fn [x] ..)
but, fortunately, that didn't affect much code.
We have a few places we're having to use s/spec*
now so the "helper macros" mentioned in your latest journal will help clean that up when they drop in GitHub.
yeah, that has further solidified today and I think will be very useful
Interesting. I never knew you could define a spec to nil
to make it go away...
Make that 2. The (s/def spec nil)
was a mistake on my part, I had to call unstrument
first (which failed because ::s/invalid
is not a valid any?
which I ran into)
oh good :)
undefining still works:
$ clj -A:test
Clojure 1.10.0
user=> (require '[clojure.spec-alpha2 :as s])
nil
user=> (require '[clojure.spec-alpha2.test :as stest])
nil
user=> (defn foo [x] x)
#'user/foo
user=> (s/fdef foo :args (s/cat :x number?) :ret number?)
user/foo
user=> (stest/instrument `foo)
[user/foo]
user=> (foo "a")
Execution error - invalid arguments to user/foo at (test.clj:129).
"a" - failed: number? at: [:x]
user=> (stest/unstrument)
[user/foo]
user=> (s/def foo nil)
user/foo
user=> (stest/instrument `foo)
[]