0

When I evaluate the following expression,

{a -> "value1", b -> "value22"} /. {Rule[x_, y_] -> Rule[x, y]}

I get {a -> "value1", b -> "value2"}, as expected.

But when I evaluate the same expression with a ToString[] wrapper around a named pattern, it is no longer recognized as a named pattern:

{a -> "value1", b -> "value2"} /. {Rule[x_, y_] -> Rule[x, ToString[y]]}

Result: {a -> y, b -> y}.

Why is y not replaced with the corresponding right-hand side values in replacement rules? How can I fix this?

verse
  • 1,287
  • 6
  • 18

0 Answers0