You're viewing version 1.2.0 of and. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (and)
  • (and x)
  • (and x & next)
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.

2 Examples top

  • 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
  • ;; See examples for "if" explaining Clojure's idea of logical true
    ;; and logical false.
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/or

    Evaluates exprs one at a time, from left to right. If a form return

  • 0
    clojure.core/if

    Please see http://clojure.org/special_forms#if

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:693 top

(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#))))
Vars in clojure.core/and: defmacro next apply concat let list seq vector

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:

(apply add [true true false true]) ;won't work
Instead, use this:
(every? identity [true  true false true])
More discussion can be found at http://osdir.com/ml/clojure/2010-01/msg01242.html

Log in to add a comment.