Skip to main content
deleted 14 characters in body; edited title
Source Link
m_goldberg
  • 108.2k
  • 16
  • 104
  • 259

UnsameQ[] UnsameQ exhibits different behavior than !SameQ[]SameQ

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*)

Thank you.

UnsameQ[] different !SameQ[]

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*)

Thank you.

UnsameQ exhibits different behavior than !SameQ

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*)
Source Link
Aharon Naiman
  • 1.2k
  • 7
  • 13

UnsameQ[] different !SameQ[]

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*)

Thank you.