clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
alexmiller 2020-03-02T02:36:32.087900Z

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

alexmiller 2020-03-02T02:41:54.088400Z

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

bbrinck 2020-03-02T15:30:29.089900Z

Ah, that’s good to know. Thanks!

norton 2020-03-02T15:14:35.089200Z

@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)

norton 2020-03-07T16:18:30.102500Z

@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).

norton 2020-03-02T15:19:06.089400Z

I’m using this version:

{:git/url "<https://github.com/clojure/spec-alpha2>"
         :sha "8498f9cb352135579b6d3a0a5d15c40e5c2647ce"}

norton 2020-03-02T15:26:50.089700Z

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)

alexmiller 2020-03-02T16:18:55.090100Z

used to work, prob broken by later changes

alexmiller 2020-03-02T16:20:18.090300Z

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

👍 1
norton 2020-03-02T16:48:56.090600Z

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])))

alexmiller 2020-03-02T17:07:07.090800Z

sorry, not sure off the top of my head