Let's say I have an expression that in held form contains a pointer to a function.
expr = Hold[2*{"FUNCTION1"} + 5];
{"FUNCTION1"}
references a pure function or combination of other functions that are verbose and would be redundant to retype. For an example, let's say the function is:
func = #^2 &
In later calculations, I want to define a new function that uses expr
with the referenced function substituted:
newfunc = ReleaseHold[expr /. {"FUNCTION1"} :> func]
5 + 2 (#1^2 &)
However, this is not what I'm after as trying to evaluate newfunc
reveals:
newfunc[5]
(5 + 2 (#1^2 &))[5]
What I'm really after is
(5 + 2*#1^2) &[5]
55
So, is there a pattern format that can be used to correctly splice in the pure function. This needs to be general as expr
won't always have the same form.