Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does if-not call "not", rather than just inverting arguments?

Tags:

clojure

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)

like image 917
damonh Avatar asked Feb 22 '17 11:02

damonh


People also ask

Why is this fallacy called denying the antecedent?

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.

What is wrong with denying the antecedent?

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.

Is Fallacy of the Inverse valid?

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.

Why is modus tollens not a fallacy?

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.


1 Answers

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.

like image 176
ntalbs Avatar answered Jan 03 '23 01:01

ntalbs