The if-not macro is implemented as:
(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)))
The first form expands to the second, and the second uses not
, so if I simplify by removing docs and the other arity, we effectively get:
(defmacro if-not
[test then else]
`(if (if ~test false true) then else))
This seems like more work than just reversing the forms. I had assumed that this would instead be:
(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 ~test ~else ~then)))
I appreciate that it's not a big deal, but is there a reason for using not
and not just inverting the forms?
PS. I believe this question may have been asked before, but I’ve been searching ask.clojure and can’t find it.