Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Misprint in the Documentation?

  • To: mathgroup at
  • Subject: [mg116613] Re: Misprint in the Documentation?
  • From: Leonid Shifrin <lshifr at>
  • Date: Mon, 21 Feb 2011 19:29:33 -0500 (EST)


It is not a misprint. With is for local constants - you can not assign
values to
symbols localized by With anywhere in the body of With, including the
You can only set their values in the declaration list (first argument of
With). This
is a general feature of With, with or without the condition.

Generally, this construct - variables shared between the body and the
is very useful at times, since it allows you to preserve the standard
of Mathematica functions returning "unevaluated" when pattern is not matched
continuing with trying other rules down the definition list), even when some
computation might have happened behind the scenes to establish the fact of

You can probably find lots of good examples for this on the mathgroup
archives, the two
I am personally aware of are

(a bit tangential, discussion is about how to implement "nested" With macro
and preserve this feature), and

which seems to be directly relevant. Also, I use this technique in my post
in this thread, where I also briefly explain its advantages:

although the thread itself is about some specific problem.



On Mon, Feb 21, 2011 at 12:20 PM, Alexey <lehin.p at> wrote:

> Hello,
> On the Documentation page ref/Condition under "More information" field
> we read: "lhs:=Module[{vars},rhs/;test] allows local variables to be
> shared between test and rhs. You can use the same construction with
> Block and With.  =BB". The hyperlink at the end of the citation directs
> at the example for Module:
> In[1]:= f[x_] := Module[{u}, u^2 /; ((u = x - 1) > 0)]
> In[2]:= f[0]
> Out[2]= f[0]
> In[3]:= f[6]
> Out[3]= 25
> This method in this example also works with Block:
> In[1]:= f[x_] := Block[{u}, u^2 /; ((u = x - 1) > 0)]
> In[2]:= f[0]
> Out[2]= f[0]
> In[3]:= f[6]
> Out[3]= 25
> But it is seemed to be irrelevant to With:
> In[1]:= f[x_]:=With[{u},u^2/;((u=x-1)>0)]
> In[2]:= f[0]
> During evaluation of In[2]:= With::lvws: Variable u$ in local variable
> specification {u$} requires a value. >>
> Out[2]= With[{u$},RuleCondition[$ConditionHold[$ConditionHold[u$^2]],(u
> $=0-1)>0]]
> Is it misprint or I loose something?

  • Prev by Date: Color grid with holes in it, to visualize overlapping mappings.
  • Next by Date: Re: NDSolve Unable to find initial conditions that
  • Previous by thread: Re: Misprint in the Documentation?
  • Next by thread: Vector Runge-Kutta ODE solver with compilation?