MathGroup Archive 2003

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

Search the Archive

RE: Pattern matches only when named

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43894] RE: [mg43873] Pattern matches only when named
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 10 Oct 2003 03:06:04 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Ken,

Because the lhs of the rule is evaluated by Mathematica giving 2_.

_ + _ -> h
2 _ -> h

And that doesn't match anything in your expression.

Use HoldPattern to prevent evaluation.

f + g /. HoldPattern[ _ + _] -> h
h

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 



From: Ken Morgan [mailto:kemorgan at vt.edu]
To: mathgroup at smc.vnet.net

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


  • Prev by Date: Re: Mouse wheel under Linux w/ 4.2/5.0
  • Next by Date: Re: 3D Plots
  • Previous by thread: Re: Pattern matches only when named
  • Next by thread: Re: Pattern matches only when named