What James meant was that you should use it like so:

=> (defn teen? [age] (< 12 age 20))
#'user/teen?
=> (teen? 50)
false
=> (teen? 10)
false
=> (teen? 14)
true
=> (if (teen? 14) "yes is a teen" "no, not a teen")
"yes is a teen"

You don't need to set up these wrappers returning true and false.  nil
and false are false in Clojure, everything else is true.  Remember that
and you'll be good to go.

DD

(2014/04/23 19:45), Roelof Wobben wrote:
> Thanks,
> 
> But something is not going right.
> 
> When delete the if as you said and have this :
> 
> (defn boolean [x]
>   (or (false? x)(nil? x))
>       false;
>       true)
> 
> (defn abs [x]
>   (< x 0)
>     (* x -1);
>     x)
> 
> (defn teen? [age]
>   (< 12 age 20)
>       true;
>       false)
> 
> Then all tests fail and if I put a if before it , they all work well.
> 
> Roelof
> 
> Op woensdag 23 april 2014 12:19:01 UTC+2 schreef James Reeves:
> 
>     (< a b c) is equivalent to (and (< a b) (< b c)), so yes, (< 12 age
>     20) is the same as 12 < age < 20.
> 
>     You could write your function more concisely as:
> 
>     (defn teen? [age]
>       (< 12 age 20))
> 
>     The "if" statement is unnecessary.
> 
>     - James
> 
> 
>     On 23 April 2014 11:11, Roelof Wobben <rwo...@hotmail.com
>     <javascript:>> wrote:
> 
>         Hello,
> 
>         I do not understand why this work.
> 
>         I have to check if someone is between 12 and 20 years.
> 
>         So after some trail and error this seems to work
> 
>         (defn teen? [age]
>           (if (< 12 age 20)
>               true;
>               false))
> 
>         Is it right it stated 12 < age <  20 ?
> 
>         Roelof
> 
>         -- 
>         You received this message because you are subscribed to the Google
>         Groups "Clojure" group.
>         To post to this group, send email to clo...@googlegroups.com
>         <javascript:>
>         Note that posts from new members are moderated - please be
>         patient with your first post.
>         To unsubscribe from this group, send email to
>         clojure+u...@googlegroups.com <javascript:>
>         For more options, visit this group at
>         http://groups.google.com/group/clojure?hl=en
>         <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+u...@googlegroups.com <javascript:>.
>         For more options, visit https://groups.google.com/d/optout
>         <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

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