Why does the second operation computes to false? Does the "or" argument function differently in clojure? If so, how should I write the operation so it computes to true regardless of where the 0 is in the argument?
(= (or 0 1) 0) ; true
(= (or 1 0) 0) ; false
(or)(or x)(or x & next)
- evaluates expressions one at a time, from left to right.
If form returns logical true value, or
returns that value and doesn't evaluate any of the other expressions, otherwise it returns the
value of the last expression or nil
if last expression are falsy
(Source: Clojure documentation ).
In first statement (= (or 0 1) 0)
the (or 0 1) return 0
because it's is logical true
( in clojure inly nil
and false
are falsy) then compare with 0
so result is true
.
In second statement (= (or 1 0) 0)
it returns 1
and compare it to 0
and returns false because they aren't equal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With