Evaluates exprs one at a time, from left to right. If a form
returns logical false (nil or false), and returns that value and
doesn't evaluate any of the other expressions, otherwise it returns
the value of the last expr. (and) returns true.
user=> (and true true) true user=> (and true false) false user=> (and false false) false user=> (and '() '()) () user=> (and '[] '[]) [] user=> (and 0 1) ; Note that this is *not* bitwise 'and' 1 user=> (and 1 0) 0 user=> (and (constantly true) (> 2 1)) true
(defmacro and
"Evaluates exprs one at a time, from left to right. If a form
returns logical false (nil or false), and returns that value and
doesn't evaluate any of the other expressions, otherwise it returns
the value of the last expr. (and) returns true."
{:added "1.0"}
([] true)
([x] x)
([x & next]
`(let [and# ~x]
(if and# (and ~@next) and#))))
Comments top
1 comment(s) for and.
Note add is a macro, so you cannot apply it. For example, there is a vector of some Boolean values [true true false true], which you want to test to see if they are all true. The code below will not work:
Instead, use this: More discussion can be found at http://osdir.com/ml/clojure/2010-01/msg01242.html