2

The documentation on the attribute OneIdentity says

OneIdentity is an attribute that can be assigned to a symbol f to indicate that f[x], f[f[x]], etc. are all equivalent to x for 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?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Praan
  • 683
  • 4
  • 15

0 Answers0