My original problem is to delete all rules starts with a[1] from SubValues[a]
For example,
{HoldPattern[a[1][2]] :> 1, HoldPattern[a[2][3]] :> 5,
HoldPattern[a[1][x_, y_]] :> x + y,
HoldPattern[a[2][x_, y_]] :> x - y, HoldPattern[a[2][x_]] :> x}
would become
{HoldPattern[a[2][3]] :> 5, HoldPattern[a[2][x_, y_]] :> x - y,
HoldPattern[a[2][x_]] :> x}
I tried to use patterns at first, but I found that when matching patterns with HoldPattern head, results become unpredictable.
I found 2 general pattern matching results with HoldPattern I don't understand (doc on HoldPattern and related did not say anything on this):
1.MatchQ[HoldPattern[a[1]], HoldPattern[_[_]]] is True, but include some names, and MatchQ[HoldPattern[a[1]], HoldPattern[a[_]]] is False.
2.MatchQ[HoldPattern[a[1]], HoldPattern[_[_]]] is True, but MatchQ[HoldPattern[a[1][1]], HoldPattern[_[_][_]]] is False.
I solved my problem with
FilterRules[SubValues[a], _?(FreeQ[#, name] &)]
But I would still like to know about matching HoldPattern expressions.
Verbatim:MatchQ[HoldPattern[a[1]], Verbatim[HoldPattern][a[_]]]will returnTrue. – Apr 17 '16 at 18:57Verbatimwork with blanks, and I have no idea whatHoldPatterndid to the expression that caused this mismatch. – vapor Apr 17 '16 at 19:00