It looks like you overgeneralized a bit. In Clojure, you should almost
always replace (if expr true false) with just expr. However, it only
applies when the last two elements are true and false in that order.

(if expr1 expr2 expr3), as you had for abs, may not usually be simplified
in that way.

On Wednesday, 23 April 2014, Roelof Wobben <rwob...@hotmail.com> wrote:

>
>
> Op woensdag 23 april 2014 14:26:14 UTC+2 schreef Tassilo Horn:
>>
>> Roelof Wobben <rwo...@hotmail.com> writes:
>>
>> > 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
>>
>> Well, the function contains three forms where the results of the first
>> two are ignored and only the value of the last one is returned.  So here
>> you need an `if`.
>>
>>   (defn abs [x]
>>     (if (< x 0)
>>       (* x -1)
>>       x))
>>
>> Bye,
>> Tassilo
>>
>> BTW: Why do you have those semicolons in your code?  That ends a
>> statement in C-like languages but in Lisps including Clojure it starts a
>> comment spanning till the end of the line.
>>
>
>
> oke,
> So if I understand everything well when I want true or false I do not need
> a if . In all other cases I need a if.
> Regarding the ; I thought I was a divider between the then and the else
>
> 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<javascript:_e(%7B%7D,'cvml','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<javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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<javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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