carlson
(Christopher Carlson)
1
What trick do I have to use to write a pattern that matches Condition? These don’t work:
MatchQ[Hold[a := b /; c], Hold[_ := _ /; _]]
MatchQ[Hold[b /; c], Hold[_ /; _]]
MatchQ[Hold[b /; c], HoldPattern[Hold[_ /; _]]]
MatchQ[Hold[b /; c], Verbatim[Hold[_ /; _]]]
carlob
(Carlo Barbieri)
2
MatchQ[Hold[b /; c], Hold[Verbatim[Condition][_, _]]]
jmichelson
(Jeremy Michelson)
3
The first 2 don’t work because the Condition on the rhs is interpreted as a condition.
The third one doesn’t work because HoldPattern doesn’t prevent the interpretation of Condition, merely evaluations.
The last one doesn’t work because Verbatim means literally. So this also stops Blank[] from matching anything but a literal Blank[].
The following also works:
In[1]:= MatchQ[Hold[b /; c], Hold[_Condition]]
Out[1]= True