Sets are treated as predicate functions which are valid when they produce a 
logically true value. Sets with logically false values nil or false will 
fail this check. This is not a spec thing, but a general thing to be aware 
of in Clojure when using sets as functions.

If you want nils, use (s/gen nil?). 
If you want falses, use (s/gen false?). 
If you want either, the simplest thing is probably (s/gen (s/nilable 
false?)), but keep in mind that the s/nilable generator is constructed to 
only produce nils 10% of the time, so you'll get 10% nils, 90% falses.

You could also use the more cumbersome (s/gen (s/nonconforming (s/or :n 
nil? :f false?))) which should give you about 50/50 mix.


On Tuesday, January 29, 2019 at 2:23:50 PM UTC-6, Bost wrote:
>
> Could anybody explain please why I can't get a sample of falses or 
> quoted nils / falses here? 
>
> foo.core> (clojure-version) 
> "1.10.0" 
> foo.core> (require '[clojure.spec.gen.alpha :as gen] 
>                    '[clojure.spec.alpha :as s]) 
> nil 
> foo.core> (gen/sample (s/gen #{'nil})) 
> Error printing return value (ExceptionInfo) at 
> clojure.test.check.generators/such-that-helper (generators.cljc:320). 
> Couldn't satisfy such-that predicate after 100 tries. 
>
>
> Other interesting and/or relevant cases are: 
>
> foo.core> (gen/sample (s/gen #{'n})) 
> (n n n n n n n n n n) 
> foo.core> (gen/sample (s/gen #{true})) 
> (true true true true true true true true true true) 
> foo.core> (gen/sample (s/gen #{'true})) 
> (true true true true true true true true true true) 
> foo.core> (gen/sample (s/gen #{false})) 
> Error printing return value (ExceptionInfo) at 
> clojure.test.check.generators/such-that-helper (generators.cljc:320). 
> Couldn't satisfy such-that predicate after 100 tries. 
> foo.core> (gen/sample (s/gen #{'false})) 
> Error printing return value (ExceptionInfo) at 
> clojure.test.check.generators/such-that-helper (generators.cljc:320). 
> Couldn't satisfy such-that predicate after 100 tries. 
> foo.core> (gen/sample (s/gen #{nil})) 
> Error printing return value (ExceptionInfo) at 
> clojure.test.check.generators/such-that-helper (generators.cljc:320). 
> Couldn't satisfy such-that predicate after 100 tries. 
>
>
> Thanx 
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to