Fork me on GitHub
#clojure-spec
<
2020-03-02
>
Alex Miller (Clojure team)02:03:32

technically, it is the clojure.core/and function in both spec 1 and 2

Alex Miller (Clojure team)02:03:54

not really going to do anything with it as the plan is for s/keys and and/or to go away in spec 2 anyways

bbrinck15:03:29

Ah, that’s good to know. Thanks!

norton15:03:35

@alexmiller I tried the following example from spec 2 wiki page but it fails with “Couldn’t satisfy such-that predicate after 100 tries”. Is this a known issue?

(gen/sample (s/gen (s/select {:a int? :keyword?} [:a])) 5)

norton15:03:06

I’m using this version:

{:git/url ""
         :sha "8498f9cb352135579b6d3a0a5d15c40e5c2647ce"}

norton15:03:50

I would like to use select with unqualified keys for schema name and select keys. Something like the following:

(s/def :foo/bar
    (s/schema {:a int? :b keyword?}))

(gen/sample (s/gen (s/select :foo/bar [:a])) 5)

Alex Miller (Clojure team)16:03:55

used to work, prob broken by later changes

Alex Miller (Clojure team)16:03:18

(gen/sample (s/gen (s/select [{:a int? :b keyword?}] [:a])) 5) should work as an alternate right now

👍 4
norton16:03:56

That works. Thank you. Any suggestions for this? It fails with “Couldn’t satisfy such-that predicate after 100 tries”.

(s/def :foo/bar
  (s/schema {:a/b string? :b keyword?}))

(gen/sample (s/gen (s/select :foo/bar [:a/b])))

Alex Miller (Clojure team)17:03:07

sorry, not sure off the top of my head

norton00:03:11

@alexmiller I was able to find the reported error (outside of the generator). The last s/def below fails with the following error:

1. Unhandled java.lang.AssertionError
   Assert failed: (every? (fn* [p1__18963#] (not (select?
   p1__18963#))) unq-specs)

                  impl.clj:  423  clojure.alpha.spec.impl/schema-impl
(s/def :foo/bar
  (s/schema {:a/b string? :b keyword?}))

(s/def :foo/baz
  (s/select :foo/bar [:a/b]))

(s/def :foo/buz
  (s/schema
   {:z :foo/baz}))

norton16:03:30

@alexmiller I tried to find a smaller failing case.

(require '[clojure.alpha.spec :as s] '[clojure.alpha.spec.gen :as gen])
;; => nil

(s/def :wf/S
  (s/schema {:s/i-001 string?
             :s/i-002 string?}))
;; => :wf/S

(s/def :wf/S1
  (s/select :wf/S [:s/i-001]))
;; => :wf/S1

(s/valid? :wf/S {:s/i-001 "1"})
;; => true

(s/valid? :wf/S {:s/i-001 1})
;; => false

(s/valid? :wf/S1 {})
;; => false

(s/valid? :wf/S1 {:s/i-002 "1"})
;; => false

(s/valid? :wf/S1 {:s/i-001 "1"})
;; => true

(s/valid? :wf/S1 {:s/i-001 1})
;; => true

(gen/sample (s/gen :wf/S1) 1)
;; Caused by clojure.lang.ExceptionInfo
;; Couldn't satisfy such-that predicate after 100 tries.)
The result of the last 2 expressions is not expected (to me).