The documentation on the attribute OneIdentity says
OneIdentityis an attribute that can be assigned to a symbolfto indicate thatf[x],f[f[x]], etc. are all equivalent toxfor the purpose of pattern matching.
Then why does the input
SetAttributes[f,OneIdentity]
MatchQ[x, f[_]]
return False? On the other hand (from the examples in the documentation), the following input returns True:
SetAttributes[f, OneIdentity]
MatchQ[a, f[x_: 0, y_]]
Is there a problem with the documentation or am I misunderstanding it?
f[__](BlankSequenceinstead ofBlank)? – J. M.'s missing motivation Jul 20 '15 at 12:06MatchQ[a,f[x_: 0, y_, __]]returnsFalseeven though there is one optional argument in the first two pattern argument positions (as stated in the linked answer).A more correct definition would be: there has to be at least one optional argument in
– Praan Jul 21 '15 at 10:12f[...]and besides optional arguments there can be at most one argument that is not optional.