Mathematica > Core Language > Expressions > Evaluation Control > HoldPattern >

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
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team
Format:   HTML  |  CDF