You're viewing version 1.2.0 of assert. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

assert

clojure.core

  • (assert x)
Evaluates expr and throws an exception if it does not evaluate to
logical true.

1 Example top

  • user=> (assert true)
    nil
    
    user=> (assert false)
    java.lang.AssertionError: Assert failed: false (NO_SOURCE_FILE:0)
    
    user=> (assert nil)
    java.lang.AssertionError: Assert failed: nil (NO_SOURCE_FILE:0)
    
    user=> (assert 0)
    nil
    
    user=> (assert [1 2 3])
    nil
    
    user=> (assert "foo")
    nil
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:3726 top

(defmacro assert
  "Evaluates expr and throws an exception if it does not evaluate to
 logical true."
  {:added "1.0"}
  [x]
  (when *assert*
    `(when-not ~x
       (throw (new AssertionError (str "Assert failed: " (pr-str '~x)))))))
Vars in clojure.core/assert: *assert* defmacro when concat list pr-str seq str when-not

Comments top

No comments for assert. Log in to add a comment.