Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: ReplaceAll question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82540] Re: ReplaceAll question
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Wed, 24 Oct 2007 04:25:45 -0400 (EDT)
  • References: <ffkf46$sh6$1@smc.vnet.net>

Yaroslav Bulatov wrote:
> b = 3;
> Hold[a[[b]]] /. {b -> c}
> 
> ReplaceAll has no effect, why?

Because 'b' gets evaluated.  So this is equivalent to:

Hold[a[[b]]] /. {3 -> c}

 > What is the recommended way of carrying
> out the replacement above?
> 

One must use HoldPattern here.

b = 3;
Hold[b] /. HoldPattern[b] -> c

-- 
Szabolcs


  • Prev by Date: Re: ReplaceAll question
  • Next by Date: Re: ReplaceAll question
  • Previous by thread: Re: ReplaceAll question
  • Next by thread: Re: ReplaceAll question