Why are the following functions
a[x___] := If[ UnsameQ[x, Null], 1, 2, 3]
b[x___] := If[ Not[SameQ[x, Null]], 1, 2, 3]
different? For example
a[]
(*1*)
a[1]
(*1*)
b[]
(*2*)
b[1]
(*1*)
In particular, why does a[] gives 1 instead of 2?
I didn't expect that also because
UnsameQ[x, y] == Not[SameQ[x, y]]
UnsameQ[x, Null] == Not[SameQ[x, Null]]
(*True*)
(*True*)
Moreover, if I define
uns[a_, b_] := UnsameQ[a, b]
nts[a_, b_] := Not[SameQ[a, b]]
the functions
c[x___] := If[nts[x, Null], 1, 2, 3]
d[x___] := If[uns[x, Null], 1, 2, 3]
are different from the previous ones:
c[]
(*3*)
c[1]
(*1*)
d[]
(*3*)
d[1]
(*1*)
Why does it happens?
The same question holds for SameQ and Not[UnsameQ]
UnsameQ[Null]andSameQ[Null]both of which returnTrue. TheBlankNullSequencespits out something akin toSequence[]if you have no match. – b3m2a1 May 31 '17 at 04:52SameQ[a, b, a]andUnsameQ[a, b, a], which are both false, as these expressions are neither all identical, nor all different. – Szabolcs May 31 '17 at 07:25e1===e2===e3givesTrueif all theeiare identical. (equivalent toSameQ[e1,e2,e3]. Of course in a set of just[e1]all of theeiare identical. No reason to returnFalse. – LLlAMnYP Jun 02 '17 at 11:15UnsameQ[e1,e2,e3]is true if no twoeiare identical. There are no twoeiinUnsameQ[e1]so no twoeiare identical. – LLlAMnYP Jun 02 '17 at 14:22