1.3.0 permalink Arrow_down_16x16

if-not

clojure.core

  • (if-not test then)
  • (if-not test then else)
Evaluates test. If logical false, evaluates and returns then expr,
otherwise else expr, if supplied, else nil.

3 Examples top

  • user=> (defn has-neg [coll] 
      (if-not (empty? coll)   ;;  = (if (not (empty? coll)) ...
        (or (neg? (first coll)) (recur (rest coll)))))
    #'user/has-neg
    
    user=> (has-neg [])
    nil 
    
    user=> (has-neg [1 2 -3 4])
    true
  • user=> (if-not (zero? 0) :then :else)
    :else
  • ;; See examples for "if" explaining Clojure's idea of logical true
    ;; and logical false.
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:702 top

(defmacro if-not
  "Evaluates test. If logical false, evaluates and returns then expr, 
  otherwise else expr, if supplied, else nil."
  {:added "1.0"}
  ([test then] `(if-not ~test ~then nil))
  ([test then else]
   `(if (not ~test) ~then ~else)))
Vars in clojure.core/if-not:
Used in 0 other vars

Comments top

No comments for if-not. Log in to add a comment.