I'm studying the source of clojure.core.
(defmacro if-not
([test then] `(if-not ~test ~then nil))
([test then else]
`(if (not ~test) ~then ~else)))
As to the second form, why not just
([test then else] `(if ~test ~else ~then)
The name denying the antecedent derives from the premise "not P", which denies the "if" clause of the conditional premise. One way to demonstrate the invalidity of this argument form is with an example that has true premises but an obviously false conclusion.
Denying the antecedent is invalid because it involves making unjustified conclusions from a conditional (or if-then) statement. A conditional statement claims that if X is true, then Y is true as well. Denying the antecedent occurs when someone concludes from such a conditional that if X is false, then Y is false too.
From the form of these arguments, we conclude that the first argument is invalid, since it is the Fallacy of the Inverse while the second argument is valid, since it is the Law of Detachment.
Like modus ponens, modus tollens is a valid argument form because the truth of the premises guarantees the truth of the conclusion; however, like affirming the consequent, denying the antecedent is an invalid argument form because the truth of the premises does not guarantee the truth of the conclusion.
This looks just a style of coding.
(if-not test then else)
(if (not test) then else)
(if test else then)
The above code will work the same way. There are multiple way to write code to do the same thing.
The author of if-not
macro might have thought that it would be better to write the code that way.
(defmacro if-not
...
([test then else]
`(if (not ~test) ~then ~else)))
When we read this code (above), we can think in the order of if
, then
, else
, quite straightforward.
(defmacro if-not
...
([test then else]
`(if ~test ~else ~then)
Yes, this will work fine. However, in terms of readability, the order then
and else
are swapped, and it might cause confusing.
That's why (in my guess) the author implemented if-not
in that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With