Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*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 2001

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

Search the Archive

Re: Replacement Rule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32092] Re: [mg32064] Replacement Rule
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sat, 22 Dec 2001 04:23:22 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

The problem is that your rule matches in more than one way and the match 
that is found first is not the one you want. There are lot sof ways to 
deal with this. Here are just a couple:

1.
In[4]:=
l2={{3,4},{5,6}};

In[5]:=
l2/.{x_Integer,y_}->x

Out[5]=
{3,5}

Here is another:

In[6]:=
Replace[l2,{x_,y_}->x,{1}]

Out[6]=
{3,5}

Andrzej Kozlowski
Toyama International University
JAPAN

On Friday, December 21, 2001, at 05:57  PM, 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[3]:= l1 /. {x_, y_} -> x
>
> Out[3]= {1, 3, 5}
>
> This is what I would expect. Now consider the following list
>
> In[4]:= l2 = {{3, 4}, {5, 6}};
>
> Then I use the same pattern/replacement rule
>
> In[5]:=l2 /. {x_, y_} -> x
>
> Out[5]= {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
>
>
>

http://platon.c.u-tokyo.ac.jp/andrzej/



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