I am having some difficulties with the ReplaceAll function.
When I write:
{1, 2, 3, 4, 5} /. x_?OddQ -> x^2
I expect:
{1,2,9,4,25}
But if I write:
x = 1;
{1, 2, 3, 4, 5} /. x_?OddQ -> x^2
I have:
{1,2,1,4,1}
How can I avoid this? I mean, even using:
x = 1;
Module[{x},{1, 2, 3, 4, 5} /. x_?OddQ -> x^2]
The output still:
{1,2,1,4,1}
Thanks in advance!
Edit: Thanks again! I never quite understood this RuleDelayed.
RuleDelayed(:>), instead ofRule(->). – Leonid Shifrin Jul 18 '13 at 14:03RuleandRuleDelayed, so you may want to check that out. – Leonid Shifrin Jul 18 '13 at 14:18