RE: Pattern matches only when named
- To: mathgroup at smc.vnet.net
- Subject: [mg43913] RE: [mg43873] Pattern matches only when named
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Sat, 11 Oct 2003 01:33:32 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: Ken Morgan [mailto:kemorgan at vt.edu] To: mathgroup at smc.vnet.net >Sent: Thursday, October 09, 2003 7:55 AM >To: mathgroup at smc.vnet.net >Subject: [mg43913] [mg43873] Pattern matches only when named > > >Just a curiosity: > >In[1]:= f + g /. u_ + _ -> h >Out[1]:= h > >but > >In[2]:= f + g /. _ + _ -> h >Out[2]:= f + g > >Why does the pattern match only when one of the Blanks has a name? > > >Thanks, >Ken > Quite simple: because f + g does not match 2 _ !! Clearly this is not what you meant, but to avoid evaluating the pattern in Rule use Hold Pattern: In[3]:= f + g /. HoldPattern[_ + _] -> h Out[3]= h -- Hartmut Wolf