How to use Evaluate inside function definition so that is acts as Evaluate only whet function is called?
This is toy exampl, where I want to define function inside another function:
Clear[y, x];
f1[a_] := Module[
{test, testF},
test = a x + 2;
testF[x_] := Evaluate[test];
testF[y]
];
f1[6]
I want result "2 + 6 y", but get "2 + 6 x"
Evaluateis completely unnecessary here -- you could just as well definetest[x_] := a x + 2. I assume your actual problem is more complicated than this, but your minimal example is not a very good one. Perhaps you should include your actual question, even if more complicated. See also What is the XY problem?. – AccidentalFourierTransform Dec 06 '18 at 02:38Clear[y, x]; f1[a_] := Module[{test, testF}, test = a x + 2; Set @@{testF[x_], test}; testF[y]]; f1[6]will resolve your problem. NoticeEvaluateis not relevant here, what's causing trouble is renaming insideModule, which has been explained in the post linked above. – xzczd Dec 06 '18 at 06:24