Ahh...  I realized my mistake very soon after I posted the question, and 
deleted it.  You must have caught it before it went away.  Your explanation 
is helpful, though.  Thanks.

On Thursday, July 21, 2016 at 1:30:56 PM UTC-5, miner wrote:
>
> It looks like you’ve got your #s misplaced.  I think you want something 
> like this:
>
> (s/and #(> % 0.0) #(< % 1.0))
>
> Of course, the first predicate expression could be replaced by `pos?`.
>
> The `s/and` returns a single spec that combines multiple specs.  Of 
> course, `clojure.core/and` is basically the logical AND of “truthy” values.
>
> The #(…) form is creating an anonymous function.  In your first case, that 
> creates a reasonable predicate, which works correctly as a spec.
>
> Your second form isn’t doing what you wanted because the anonymous 
> function notation is wrapping the whole `s/and` combining form, and in that 
> context the tests aren't syntactically the appropriate predicates.  You’re 
> getting an extra level of nesting and bad tests.
>
> I suspect that the confusion comes from the similarity between a predicate 
> and a spec.  In a sense, a predicate function is the simplest form of a 
> spec.  However, you need a special way of combining multiple specs, not 
> just the plain logical `and` combination.  So we have `s/and` to do the job.
>
>
>
> On Jul 21, 2016, at 1:23 PM, Mars0i <[email protected] <javascript:>> 
> wrote:
>
> With Clojure 1.9.0-alpha10:
>
>
>
>
>
>
>
>
> *user=> (s/def ::interval-with-cloj-and #(and   (> % 0.0) (< % 
> 1.0)))user=> (s/def ::interval-with-spec-and #(s/and (> % 0.0) (< % 
> 1.0)))user=> (s/valid? ::interval-with-cloj-and 1.0)false*That's what I 
> expected.
>
>
> *user=> (s/valid? ::interval-with-spec-and 1.0)true*
>
> That's not what I expected.
>
> In fact, as far as I can tell, (valid? ::interval-with-spec-and x) will 
> return true for any number x.  What does spec/and mean, then?  I thought 
> that in this context it would mean the same as Clojure's normal 'and'.  
> That's what the first example of its use in the Clojure.spec Guide seems to 
> show.  I must be misunderstanding something basic and perhaps obvious.
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to