Why does the following match?
MatchQ[HoldPattern[f], HoldPattern[_]] True But the following does not:
MatchQ[HoldPattern[f], HoldPattern[f]] False Or:
MatchQ[HoldPattern[f[1]], HoldPattern[f[_]]] False The first one matches because HoldPattern just prevents the pattern from evaluation, so it is equivalent to
MatchQ[HoldPattern[f], _] (* True *) The second one does not match because it is, again, equivalent to
MatchQ[HoldPattern[f], f] (* False *) What you are probably looking for is Verbatim.
MatchQ[HoldPattern[f], Verbatim[HoldPattern[f]]] (* True *) f compared to f, but instead HoldPattern[f] compared to f, which is obviously not the same. HoldPattern in the first argument does not have any special meaning, it is just this exact expression. $\endgroup$ In[82]:= MatchQ[HoldPattern[f], Verbatim[HoldPattern][f]] Out[82]= True It makes no difference in this example, but there can be cases where it is only the HoldPattern that should be verbatimmed (to make up a term). $\endgroup$
Verbatimto "inactivate" pattern expression to make it match, something likeMatchQ[HoldPattern[f], Verbatim[HoldPattern[f]]]. $\endgroup$