How should I use replace so that
f[x_] := x^2
Replace[f[3], 3 -> 1]
OUT = 9
evaluates to 1, instead of 9? This way, the replacement of the argument is done before the call to the function
Activate@Replace[Inactive[f][3],3->1, Infinity]
1
or
Replace[Hold@f[3], 3 -> 1, Infinity] // ReleaseHold
1
Replace
,Unevaluated
and Inactive
. Btw, which search terms did you use to get the links you posted?
$\endgroup$
code:"/." code:unevaluated is:answer
but most of the time I feel like stumbling upon the right post is mostly blind luck; this is why I take so much time adding all the Related: links, because I often find things faster by following the network of connected posts.
$\endgroup$
Commented
May 26, 2016 at 18:12
Replace[Hold@f[3], 3 -> 1, Infinity] // ReleaseHold
? $\endgroup$ReplaceAll[Unevaluated[f[3]], 3 -> 1]
? $\endgroup$