How can we define a function that works like f[x_]=ComputeSomething[x]
and treats x
as a variable that does not have a value? We could call this function LocalSet
and the computation should be done when the assignment is made as in the following example.
var=3;
LocalSet[f[var_],Normal[Series[Exp[var],{var,0,3}]]];
DownValues[f]
(*
---> {HoldPattern[f[var_]]:>1+var+var^2/2+var^3/6}
*)
var
(*
---> 3
*)
Notice I don't want to be limited to a pattern variable (x_
). The function called LocalSet
should figure out what symbols are used for patterns and evalute the right side with those variables in a Block
construct.