       Re: Replacement Rule

• To: mathgroup at smc.vnet.net
• Subject: [mg32074] Re: [mg32064] Replacement Rule
• From: Ken Levasseur <Kenneth_Levasseur at uml.edu>
• Date: Sat, 22 Dec 2001 04:22:46 -0500 (EST)
• References: <200112210857.DAA25218@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Brian:

Pattern matching works from the top and proceeds downward.   Since the
whole expression {{3, 4}, {5, 6}} matches {x_,y_}, you're getting the
first pair, {3, 4}.   One way to fix this if you are working only with
numbers is to use RuleDelayed:
{x_,y_}:>x/;NumberQ[x]

Ken Levasseur
Math Sciences
UMass Lowell

Brian Higgins wrote:

> I have the following list
>
> l1={{1,2},{3,4},{5,6}};
>
> and then I operate on it with the following pattern/replacement rule
>
> In:= l1 /. {x_, y_} -> x
>
> Out= {1, 3, 5}
>
> This is what I would expect. Now consider the following list
>
> In:= l2 = {{3, 4}, {5, 6}};
>
> Then I use the same pattern/replacement rule
>
> In:=l2 /. {x_, y_} -> x
>
> Out= {3, 4}
>
> I was hoping to get
>
> {3,5}
>
> What am I missing? The FullForm of l2 is basically the same structure
> as l1, as far as I can tell....
>
> Brian

```

• Prev by Date: Re: solutions that are not solutions
• Next by Date: Re: Solutions that are not solutions
• Previous by thread: Re: Replacement Rule
• Next by thread: Re: Replacement Rule