Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: Strange ReplaceAll behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36793] Re: [mg36774] Strange ReplaceAll behavior
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Thu, 26 Sep 2002 04:56:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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