Re:Function Doesn't Evaluate Local Variables?
- To: mathgroup at smc.vnet.net
- Subject: [mg124730] Re:Function Doesn't Evaluate Local Variables?
- From: Ted Ersek <ersekt at md.metrocast.net>
- Date: Fri, 3 Feb 2012 02:06:47 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <000501cce199$a3b3d7a0$eb1b86e0$@md.metrocast.net>
Brentt wanted to make a function that returns a pure function. Below I provide foo[n,new] which is simpler than the example he used.
foo[n_,new_]:=With[{n1=n,nn=new},ReplacePart[#,n1->nn]&]
In[2]:= foo[Index, a Sin[x]]
Out[2]= ReplacePart[#1 ,Index->a Sin[x]]&
The next two examples show how you can use With to evaluate part of a held expression.
In[5]:= With[{y=2.3+1.5}, Hold[4+2^2+y-6/2]]
Out[5]=Hold[4 + 2^2 + 3.8 - 6/2]
In[6]:= y=2.1+1.1;
With[{y=y},Hold[4+2^2+y-6/2]]
Out[7]=Hold[4 + 2^2 + 3.2 - 6/2]
Ted Ersek
See my Mathematica tips & tricks at
http://www.verbeia.com/mathematica/tips/Tricks.html