18
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ I reported this issue to WRI some years ago, but never received a diagnosis. $\endgroup$ – WReach Jan 22 '15 at 15:16
  • 6
    $\begingroup$ Interesting. Yes, probably a bug. I'll try to have a look when I get a chance. $\endgroup$ – Daniel Lichtblau Jan 22 '15 at 15:57
  • $\begingroup$ To my interest MatchQ[{1, 2}, {PatternSequence[a_, b_.]}] throws messages but returns True. $\endgroup$ – Mr.Wizard Jan 23 '15 at 23:01
  • $\begingroup$ @Mr.Wizard Working on it (and the issue from the original post). $\endgroup$ – Daniel Lichtblau Jan 23 '15 at 23:15
  • 1
    $\begingroup$ @Daniel i.stack.imgur.com/k7L5x.gif $\endgroup$ – Mr.Wizard Jan 23 '15 at 23:18
8
$\begingroup$

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]}]  
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.