       Re: With[{software=Mathematica}, Frustration]

• To: mathgroup at smc.vnet.net
• Subject: [mg24370] Re: With[{software=Mathematica}, Frustration]
• From: "Drago Ganic" <drago.ganic at in2.hr>
• Date: Wed, 12 Jul 2000 23:13:11 -0400 (EDT)
• References: <8k3of0\$428@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

well in my practical experience with Mathematica (a Year of hobby learning) the subject to this post you have choose is quite correct. The only suggestion I can give You is to buy a lot of books (I would like to know how many non-genious people have learned the deep basics of Mathematica only from the Mathematica book).

Doing so I can give you the answer:

In:=Attributes[With]
Out= {HoldAll, Protected}

In:= Attributes[ReplaceAll]
Out={Protected}

As you can see "With" does not evaluate c,  therefore {a->2, b->3} acts on c, and not on a*b (like  in "ReplaceAll").

If you want that "With" behaves the same as "ReplaceAll" you schould use "Evaluate" ....

In:= With[{a = 2, b = 3}, Evaluate[c]]
Out=6

or if you want that "ReplaceAll" behaves the same as "With" you schould use "Unevaluated"

In:= Unevaluated[c] /. {a -> 2, b -> 3}
Out= a b

as Stephen said in The Book (you have not quooted the * ... * part ):

*Except for the question of when x and body are evaluated*, With[ax = aa, body] works essentially like body /. x -> a.

Greeting from Croatia,
Drago Ganic

"AES" <siegman at stanford.edu> wrote in message news:8k3of0\$428 at smc.vnet.net...
> Pages 359-360 of The Mathematica Book says (admittedly, taken a little
> out of context),
>
>    "You can think of  With  as a generalization of the /. operator. . ."
>
> and
>
>    " With[{x=x0}, body]  works essentially like body /. x->x0 . . . "
>
> Great, looks neat, let's try it for evaluating expressions without
> permanently setting the variables in them:
>
>    In:= c = a b
>
>    Out= a b
>
>    In:= c
>
>    Out= a b
>
>    In:= c /. {a -> 2, b -> 3}
>
>    Out= 6
>
>    In:= With[{a = 2, b = 3}, c]
>
>    Out= a b
>
> *Not* what I was hoping for  . . .
>

```

• Prev by Date: Re: l'Hopital's Rule
• Next by Date: Re: How to use BestFitParameters?
• Previous by thread: Re: With[{software=Mathematica}, Frustration]
• Next by thread: Re: With[{software=Mathematica}, Frustration]