Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14161 > unrolled thread

Re: "Programming With Mathematica" Exercise help

Started byBill Rowe <readnews@sbcglobal.net>
First post2013-04-12 06:15 +0000
Last post2013-04-14 00:36 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: "Programming With Mathematica" Exercise help Bill Rowe <readnews@sbcglobal.net> - 2013-04-12 06:15 +0000
    Re: "Programming With Mathematica" Exercise help plank.in.sequim@gmail.com - 2013-04-14 00:36 +0000

#14161 — Re: "Programming With Mathematica" Exercise help

FromBill Rowe <readnews@sbcglobal.net>
Date2013-04-12 06:15 +0000
SubjectRe: "Programming With Mathematica" Exercise help
Message-ID<kk88q6$c0l$1@smc.vnet.net>
On 4/11/13 at 4:13 AM, plank.in.sequim@gmail.com wrote:

>I'm loving Paul Wellin's book "Programming with Mathematica: An
>Introduction" and am trying to diligently do all the exercises.
>Most of them have answers in the back but I'm stuck on Section 4.2,
>Exercise 2 and there's no answer given.  It gives the following
>Mathematica code:

>z = 11; a = 9; z + 3 /. z -> a

>14

>So "z+3" is being evaluated to 14 and then the substitution has no
>effect. He asks how to "use the Hold function in the compound
>expression to obtain a value of 12".

If I wanted to evaluate an expression with z using a different
value than what had been assigned to it without reseting it, I
would use Block not Hold. That is:

In[1]:= z = 11;
a = 9;
Block[{z}, z + 3 /. z -> a]

Out[3]= 12

Likely there is a way to accomplish the same using Hold, but it
seems to me Block is more specifically designed for this type of task.

[toc] | [next] | [standalone]


#14179

Fromplank.in.sequim@gmail.com
Date2013-04-14 00:36 +0000
Message-ID<kkctmb$7et$1@smc.vnet.net>
In reply to#14161
This is a great answer!  I think it's the most elegant.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web