RE: Replacement Rule
- To: mathgroup at smc.vnet.net
- Subject: [mg32094] RE: [mg32064] Replacement Rule
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Sat, 22 Dec 2001 04:23:27 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
It's the kind of problem one finds when working with patterns. The thing is, the pattern {x_, y_} matches each element of your list, but the list itself as well: the list has two elements! Try this In[1]:= l2 = {{3, 4}, {5, 6}}; In[2]:= l2 /. {x_?NumericQ, y_} -> x Out[2]= {3, 5} This checks for patterns which match lists with numeric elements, i.e., not lists themselves. Tomas Garza Mexico City > -----Original Message----- > From: Brian Higgins [mailto:bghiggins at ucdavis.edu] To: mathgroup at smc.vnet.net > Sent: Friday, December 21, 2001 12:58 AM > To: mathgroup at smc.vnet.net > Subject: [mg32094] [mg32064] Replacement Rule > > > 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 >