MathGroup Archive 2001

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

Search the Archive

Re: Replacement Rule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32080] Re: Replacement Rule
  • From: Tom Burton <tburton at cts.com>
  • Date: Sat, 22 Dec 2001 04:22:55 -0500 (EST)
  • References: <9vuuha$onq$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Fri, 21 Dec 2001 09:14:18 +0000 (UTC), in comp.soft-sys.math.mathematica you wrote:

>L2 = {{3, 4}, {5, 6}};
...
>L2 /. {x_, y_} -> x

ReplaceAll (/.) operates on all levels of an expression from the top down (please read on-line help). Your entire list of length 2 fits the pattern, so the replacement takes place at the top level 0, whereas you intend replacement at level 1.

There are several ways to make your pattern more specific to avoid replacement at level 0. For example, you could write

L2 /. {x_Integer,y_} :> x

The solution I like best is to tell Mathematica explicitly that you want replacement only at level 1:

Replace[L2, {x_, y_} :> x, 1]

Tom Burton


  • Prev by Date: Re: Replacement Rule
  • Next by Date: Re: bisection method
  • Previous by thread: Re: Replacement Rule
  • Next by thread: RE: Replacement Rule