Why did MatchQ[a + b + c, Plus[x_, y_]
is considered true?
In my opinion, it should only consider 2 elements within Plus
, such as MatchQ[a + b, Plus[_, _]]
true.
Why is this MatchQ[a + b, Plus[_, _]]
false?
Where did I get wrong? Please point out.
HoldPattern
is simply not working. And How can I makeMatchQ[a + b, Plus[_, _]]
true? $\endgroup$MatchQ[a + b, HoldPattern[Plus[_, _]]]
works for me. $\endgroup$MatchQ[(a + b + c), Plus[_, _, _]] // HoldPattern
I am new toHoldPattern
. Sorry for this. $\endgroup$HoldPattern
is wrapped around the pattern which you don't want to evaluate. It may be a good idea for you to read more on the language core / basics. You can search this site for resources, there are plenty of recommendations. $\endgroup$HoldPattern
$\endgroup$