Skip to main content

bugs - Unexpected pattern matching behaviour: PatternSequence vs. Optional


Bug fixed in 10.1





Consider the following pattern-matching expressions:


MatchQ[{1, 2}, {a_, b_}]                     (* True *)
MatchQ[{1, 2}, {a_, b_:0}] (* True *)
MatchQ[{1, 2}, {PatternSequence[a_, b_]}] (* True *)
MatchQ[{1, 2}, {PatternSequence[a_, b_:0]}] (* False *)

The last result surprises me. I would have expected it to return True just like the others. I suspect a bug, but does this behaviour conform to some pattern-matching principle that I have overlooked?



Answer



Fixed in 10.1 (windows)



Mathematica graphics




Mathematica graphics


code


MatchQ[{1, 2}, {a_, b_}]                     
MatchQ[{1, 2}, {a_, b_: 0}]
MatchQ[{1, 2}, {PatternSequence[a_, b_]}]
MatchQ[{1, 2}, {PatternSequence[a_, b_: 0]}]

Comments