MathGroup Archive 2002

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

Search the Archive

Re: Strange ReplaceAll behavior


You really should read about the difference between := (SetDelayed) and 
= (Set).

When you enter your definition

f[x_]:=(a+b) /. ru[a]

the right hand side is not evaluated.  So next when you evaluate f[c] 
you get

(a+b)/.ru[a] and only now ru[a] is evaluated, thus giving you 
(a+b)/.a->x which is b+x

There are several ways to get what you want. One is to use = instead of 
:=, another to force evaluation of the right hand side with

f[x_]:=Evaluate[(a+b) /. ru[a]]

yet another to insert the actual rule in the definition of f:

f[x_]:=(a+b) /. a->x



Andrzej Kozlowski
Toyama International University
JAPAN



On Wednesday, September 25, 2002, at 02:50 PM, Lawrence A. Walker Jr. 
wrote:

> Hi,
>
> For the life of me I am not sure why the following is not working in my
> v. 4.2:
>
> ru[a]=a->x;
> f[x_]:=(a+b) /. ru[a];
>
> Why do I get
> f[c] = b+x
>
> and not
> f[c] = b+c?
>
> What gives?
>
> Thanks,
> Lawrence
>
> -- 
> Lawrence A. Walker Jr.
> http://www.kingshonor.com
>
>
>



  • Prev by Date: Real Time Animation
  • Next by Date: RE: Strange ReplaceAll behavior
  • Previous by thread: Re: Strange ReplaceAll behavior
  • Next by thread: RE: Strange ReplaceAll behavior