RE: ReplaceAll doesn't replace
- To: mathgroup at smc.vnet.net
- Subject: [mg32591] RE: [mg32550] ReplaceAll doesn't replace
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Wed, 30 Jan 2002 03:19:14 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
-----Original Message----- > From: Ken Morgan [mailto:kmorga51 at calvin.edu] To: mathgroup at smc.vnet.net > Sent: Saturday, January 26, 2002 10:08 AM > Subject: [mg32591] [mg32550] ReplaceAll doesn't replace > > > I understand how the following will replace x with the list > > #^2 & /@ (x /. x -> {a, b, c}) > > to generate > > {a^2, b^2, c^2} > > But, why isn't x replaced at the beginning of the evaluation in the > following > > (#^2 & /@ x) /. x -> {a, b, c} > > since it generates > > {a, b, c} > > What I really want to know is: What is it about the Function > function that > doesn't allow ReplaceAll to "replace all" at the beginning of > an evaluation? > > Thanks, > Ken Morgan > kmorga51 at calvin.edu > > Ken, the order of evaluation is different from what you suppose. ReplaceAll evaluates its argments, so In[8]:= (#^2 & /@ x) Out[8]= x Nothing is Mapped on an atom, so x is reproduced. Next In[9]:= x /. x -> {a, b, c} Out[9]= {a, b, c} but: In[10]:= Unevaluated[(#^2 & /@ x)] /. x -> {a, b, c} Out[10]= {a^2, b^2, c^2} -- Hartmut Wolf