From Mathematica's own documentation:
{g[1],Hold[g[1]]}/.g[n_]:>n+1
leads to
{2, Hold[1 + 1]}
My question: is there a way to protect subexpressions from being replaced by ReplaceAll? I am using composite constructs as variables, like
v[a, b]
and would like to be able to do stuff like this
v[a, b] + a - b /. {a -> x, b -> y}
leading to
v[a, b] + x - y
and not
v[x, y] + x - y
without complicated patterns. Unfortunately, using Replace and level specifications is not option.
This idiom
v[a, b] + a - b /. {catch_v -> catch, a -> x, b -> y}
works, as 'catch_v -> catch' prohibits the subsequent rules to be applied to v. But I would rather like to prohibit the replacement on the expression level (with some kind of Hold or HoldForm expression). Is this possible?