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
. TheBlankNullSequence
spits out something akin toSequence[]
if you have no match. $\endgroup$ – b3m2a1 May 31 '17 at 4:52SameQ[a, b, a]
andUnsameQ[a, b, a]
, which are both false, as these expressions are neither all identical, nor all different. $\endgroup$ – Szabolcs May 31 '17 at 7:25e1===e2===e3
givesTrue
if all theei
are identical. (equivalent toSameQ[e1,e2,e3]
. Of course in a set of just[e1]
all of theei
are identical. No reason to returnFalse
. $\endgroup$ – LLlAMnYP Jun 2 '17 at 11:15