Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8313
| From | Ted Ersek <ersekt@md.metrocast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re:Function Doesn't Evaluate Local Variables? |
| Date | 2012-02-03 07:08 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jgg15a$bl9$1@smc.vnet.net> (permalink) |
| 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
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re:Function Doesn't Evaluate Local Variables? Ted Ersek <ersekt@md.metrocast.net> - 2012-02-03 07:08 +0000
csiph-web