5
$\begingroup$

This question already has an answer here:

Why isn't the first one True in:

MatchQ[{1}, Optional[{__Integer}, {2}]]
MatchQ[{1}, Optional[{_Integer}, {2}]]
MatchQ[{1}, {__Integer}]

False

True

True

or in:

MatchQ[{1}, p : {__Integer} : {2}]
MatchQ[{1}, p : {_Integer} : {2}]
MatchQ[{1}, p : {__Integer}]

False

True

True

p:v is a pattern object that represents an expression of the form p, which, if omitted, should be replaced by v.

So my guess was that

MatchQ[{1}, Optional[{__Integer}, {2}]]

should be equivalent to:

MatchQ[{1}, {__Integer}]

And even if you can explain that, why are middle examples True?

$\endgroup$

marked as duplicate by Kuba May 30 '17 at 12:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ The first one returns False. I am using version 11.1.1. But the others are True $\endgroup$ – happy fish May 30 '17 at 12:23
  • $\begingroup$ @happyfish I meant it should be True, sorry for confusion :) $\endgroup$ – Kuba May 30 '17 at 12:37
  • $\begingroup$ Duplicate of mathematica.stackexchange.com/q/124801/121? $\endgroup$ – Mr.Wizard May 30 '17 at 12:53
  • $\begingroup$ @Mr.Wizard correct, missed that one. $\endgroup$ – Kuba May 30 '17 at 12:54