Roelof, Your abs definition doesn't have an (if), so those statements are just executed in order, and the last one 'x' is the return value for the whole thing.
Probably what you want is: (defn abs [x] (if (pos? x) x (- x))) user=> (abs -2) 2 user=> (abs 2) 2 user=> (abs 0) 0 marc On Wed, Apr 23, 2014 at 7:48 AM, Roelof Wobben <rwob...@hotmail.com> wrote: > > > Op woensdag 23 april 2014 13:23:17 UTC+2 schreef David Della Costa: > >> 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 > > > > Thanks, > > The only thing which is failing now is this one ; > > (defn abs [x] > (< x 0) > (* x -1); > x) > > I keep getting -2 as answer where it must be 2 > > Roelof > > > -- > 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. > -- 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.