This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

HoldPattern

HoldPattern[expr]
is equivalent to expr for pattern matching, but maintains expr in an unevaluated form.
  • The left-hand sides of rules are usually evaluated, as are parts of the left-hand sides of assignments. You can use HoldPattern to stop any part from being evaluated.
Set up a pattern whose left-hand side is kept unevaluated:
Use the pattern:
Make a definition without the argument of being evaluated:
Log autoevaluates to Log[b]/Log[a], so there is a match:
Cases finds elements that match patt; use HoldPattern to find rules:
Set up a pattern whose left-hand side is kept unevaluated:
In[1]:=
Click for copyable input
Out[1]=
Use the pattern:
In[2]:=
Click for copyable input
Out[2]=
 
Make a definition without the argument of being evaluated:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
 
Log autoevaluates to Log[b]/Log[a], so there is a match:
In[1]:=
Click for copyable input
Out[1]=
 
Cases finds elements that match patt; use HoldPattern to find rules:
In[1]:=
Click for copyable input
Out[1]=
New in 3