Re: Evaluate[] not needed in With[]
- To: mathgroup at smc.vnet.net
- Subject: [mg62984] Re: [mg62966] Evaluate[] not needed in With[]
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Sat, 10 Dec 2005 06:02:53 -0500 (EST)
- References: <200512091010.FAA05504@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Dec 9, 2005, at 5:10 AM, Steven T. Hatton wrote: > I started looking at Dr. Maeder's _Programming in Mathematica_, and > was > doing quite well understanding everything until I got to the first > example > in the first section of the first chapter. He gives an example of > using > ParametricPlot and tells us "Because ParametricPlot evaluates its > arguments > in a nonstandard way, we need to force evaluation of the variable > hline by > wrapping in into Evaluate[]." He later tells me I don't need to do > that > for a "constant" in a With[] expression. The following is a cobbled > together example showing both forms: > > Clear[z, x, y, cz, hlines, vlines]; > z = x + y I; > cz = {Re[z], Im[z]}; > hg = With[{hlines = Table[N[cz], {y, -1, 1, 2/8}]}, > ParametricPlot[hlines, {x, -Pi/2, Pi/2}, > DisplayFunction -> Identity][[1]] > ]; > vlines = Table[N[cz], {x, -Pi/2, Pi/2, Pi/12}]; > vg = ParametricPlot[Evaluate[vlines], {y, -1, 1}, > DisplayFunction -> Identity][[1]]; > Show[Graphics[Join[hg, vg], AspectRatio -> Automatic, Axes -> True]] > > I can read the words, and follow the instructions, but I still don't > understand _why_ the version in the With[] expression doesn't need the > Evaluate[]. Is there a way to _explain_ this behavior, or do I > simply need > to memorize the rule by rote? With has the attribute HoldAll and works by replacing terms in the second expression with the values specified in the first argument. In effect With is equivalent to ReleaseHold[Hold[expr]/.ReleaseHold[Apply[Rule,Hold[{x=x0,y=y0,...}]], {2}]] So one can infer how With works by studying the above expression. The Evaluate is therefore unnecessary because the expression has already been substituted by the With but without the With the HoldAll attribute of ParametricPlot necessitates forcing evaluation. The part about With's attributes and how it works is from the Help browser, specifically the second and fourth bullet points. There are some technicalities with respect to how the Apply statement would be written, as explained by the third bullet point, the single Replace is probably a bit of an oversimplification but it suffices for this case. Regards, Ssezi
- References:
- Evaluate[] not needed in With[]
- From: "Steven T. Hatton" <hattons@globalsymmetry.com>
- Evaluate[] not needed in With[]