Message Boards Message Boards


What's the secret to matching Condition?

Posted 9 years ago
2 Replies
7 Total Likes
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[_ /; _]]]
2 Replies
MatchQ[Hold[b /; c], Hold[Verbatim[Condition][_, _]]]
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 
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract