MathGroup Archive 2003

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

Search the Archive

RE: Pattern matches only when named


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