Evaluates expr and throws an exception if it does not evaluate to
logical true.
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
(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)))))))
([x message]
(when *assert*
`(when-not ~x
(throw (new AssertionError (str "Assert failed: " ~message "\n" (pr-str '~x))))))))
Comments top
No comments for assert. Log in to add a comment.