I do not understand the UnsameQ[]
behavior below. (I need UnsameQ[]
as I may have variables in the array.)
{-7, 3, 2} /. x_ /; x == 3 -> w
(*{-7, w, 2}*)
{-7, 3, 2} /. x_ /; x != 3 -> w
(*{w, 3, w}*)
{-7, 3, 2} /. x_ /; x === 3 -> w
(*{-7, w, 2}*)
{-7, 3, 2} /. x_ /; x =!= 3 -> w
(*w*)
{a} /. _ -> "who said it works only at the first level?"
and{} != 3
vs{} =!= 3
. $\endgroup$UnsameQ[]
case, the entire{-7,3,2}
is becomingx
(/after/ the first level?) and not the same as 3. Why does that not continue withUnequal[]
? (For that matter, I am a tad stymied why{}!=3
does not return False.) $\endgroup$! SameQ[]
would be{-7, 3, 2} /. x_ /; ! (x === 3) -> w
, which returns the same asUnsameQ[]
. But! Equal[]
is different thanUnsameQ[]
, as your 2nd and 4th examples show. $\endgroup$Replace[list, x_ /; x =!= 3 -> w, 1]
orReplace[list, x_ /; x =!= 3 -> w, Infinity]
$\endgroup$!SameQ[]
. I see that!Equal[]
andUnsameQ[]
are different, my questions are: why? and why should I have known that? Also, I would appreciate a pointer to some documentation, explaining why{}!=3
does not returnFalse
. Thank you. $\endgroup$