I wish to take some expression containing instances of Pattern[]
, and rename the variables of those patterns based on evaluation featuring the variable.
Let’s say my renaming function is
f[s_Symbol] := Symbol[ SymbolName[s], "2" ]
which just appends 2 to symbol names:
f[a] >>> a2
If I try to replace Pattern
variables with this function (or any expression), that expression remains unevaluated!
a_ /. a :> f[a] >>> Pattern[ f[a], _ ]
I assume Pattern
holds its first argument.
Naturally my example is strange since simplified; I really intend to replace any symbol (which may or may not be featured in a Pattern
) which satisifes certain properties.
a_ /. s_Symbol /; someTest[s] :> f[s] >>> Pattern[ f[a], _ ]
How can I force Pattern
to evaluate its first argument after my substitution?
I cannot just insert an Evaluate
into the RHS of my DelayedRule
(though that solves my first example), since this just violates the rule delay, and invokes f[s]
.