Using Integrate, I can do any of the following:
Integrate[x^2, {x,0,2}]
Clear[f]; f[x_]:=x^2; Integrate[f[x],{x,0,2}]
Clear[f]; f=x^2; Integrate[f,{x,0,2}]
and all three return 8/3, as they should. When I asked this question, the accepted answer works, as I just discovered, in the first and second cases, but not in the third. In the third case, using HoldAll prevents the first argument from being properly evaluated. For reference, a simplified version of the solution proposed in the above referenced question, which simply returns the given function with variable name translated to an internal local, is:
Clear[i];
i[fn_, intvl_] :=
Module[{ii, externalSymbol, localVar},
externalSymbol =
ReleaseHold[Hold[intvl] /. {x_, y__} :> HoldPattern[x]];
ii = ReleaseHold[Hold[fn] /. externalSymbol :> localVar];
ii];
SetAttributes[i, HoldAll];
When invoked as above (with i in place of Integrate), the three invocations return respectively localvar$<number>^2, localvar$<number>^2, x^2.
Is it possible to define i so that its parameter interpretation behavior matches that of Integrate?
Integrateis notHoldAll. p.s. take a look attableimplementation in this answer: https://mathematica.stackexchange.com/a/567/5478 – Kuba Apr 12 '18 at 12:54