ClojureDocs

Nav

Namespaces

when-not

clojure.core

Available since 1.0 (source)
  • (when-not test & body)
Evaluates test. If logical false, evaluates body in an implicit do.
5 Examples
;; build tuples over sets with the same cardinality 
(map
  #(when-not (= %2 %3) [%1 %2 %3])
    (iterate inc 0)   ; a lazy list of indecies
    [:a :b :c]
    [:a :a :a])
;;=> (nil [1 :b :a] [2 :c :a])
;; See examples for "if" explaining Clojure's idea of logical true
;; and logical false.
;; when-not is similar to unless (in other languages).
;; An alias can be provided with a macro
(defmacro unless [& args] `(when-not ~@args))

(map #(unless (= %2 %3) [%1 %2 %3])
  (iterate inc 0)    ; a lazy list for indecies
  [:a :b :c]
  [:a :a :a]) 
;;=> (nil [1 :b :a] [2 :c :a])
(when-not false 2)
;; 2
(when-not true 2)
;; nil
See Also

Evaluates test. If logical true, evaluates body in an implicit do.

Added by Havvy

bindings => binding-form test When test is true, evaluates body with binding-form bound to the va...

Added by mmwaikar

Evaluates test.

Added by jafingerhut
0 Notes
No notes for when-not