MathGroup Archive 2013

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

Search the Archive

Re: "Programming With Mathematica" Exercise help

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130452] Re: "Programming With Mathematica" Exercise help
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 12 Apr 2013 02:16:05 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

On 4/11/13 at 4:13 AM, plank.in.sequim at 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.




  • Prev by Date: Re: Timing puzzle
  • Next by Date: Re: "Programming With Mathematica" Exercise help
  • Previous by thread: Re: "Programming With Mathematica" Exercise help
  • Next by thread: Re: "Programming With Mathematica" Exercise help