On Thursday, September 26, 2019 at 7:41:20 AM UTC-5, Markus Agwin wrote:
>
> Consider the following cloure.spec-alpha2 example:
>   
> (def v [0])
> (s/def ::thevec vector?)
> (s/def ::data (s/coll-of number? :kind ::thevec))
>

:kind is expected to be a predicate, not a spec. The doc string (in 
s/every) says ":kind - a pred that the collection type must satisfy, e.g. 
vector?"

so this should be:

(s/def ::data (s/coll-of number? :kind vector?))

With the prior, you're getting the keyword ::thevec as the predicate - that 
will look ::thevec up in whatever you pass it when used as a predicate.
 

> (s/valid? ::data v) ;;=> returns false, my expectation is that it should 
> return true
>

This matches above interpretation - (::thevec [0]) yields nil
 

> (s/explain ::data v) ;;=> prints "Success!", which inconsistent to s/valid?
>

Agreed that's confusing. I think it's because the keyword as predicate 
returns nil instead of false but there is probably something to clean up 
here.
 

>
> (s/def ::data2 (s/coll-of number? :kind vector?))
> (s/valid? ::data2 v) ;;=> returns true, as expected
>
> I expect (s/valid? ::data v) to return true, but it returns false. 
> Moreover, s/explain prints "Success!" which is inconsistent to s/valid? for 
> this example.
> If I replace :kind ::thevec by :kind vector?, everything is fine. Why is 
> that (the spec documentation says: ":kind - a predicate or spec").
>

The docs were wrong at one point in time, but this was fixed a while ago, 
only preds are supported here.  Where are you seeing the old docs? 

https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html#clojure.spec.alpha/every
 
doesn't have that and you won't see it in docstrings of current spec or 
spec 2 versions

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/2a01dc26-1e98-4d9a-becf-2c0d684e783a%40googlegroups.com.

Reply via email to