and

added
1.0

ns
clojure.core

type
macro

(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.

                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

            
                ;; See examples for "if" explaining Clojure's idea of logical true
;; and logical false.
            
                ; Note that, and does not evaluate if the first value is false
user=> (and false nil)
false

user=> (and nil false)
nil

user=> (and false (println "foo"))
false

user=> (and (println "foo") false)
foo
nil
            
                ; From the Clojure 1.9 source code.
(defn qualified-keyword?
  "Return true if x is a keyword with a namespace"
  [x] (and (keyword? x) (namespace x) true))

; Note how the return value of and is value of the last expression.
user=> (qualified-keyword? :hi/there)
true

; If we instead define the function as:
(defn qualified-keyword?
  [x] (and (keyword? x) (namespace x)))
; we get the namespace as return value:
user=> (qualified-keyword? :hi/there)
"hi"