What does _. mean in patterns?
FullForm
will show you how an expression is really interpreted,
In[5]:= FullForm[_.]
Out[5]= Optional[Blank[]]
This tells you you need to look at Optional
and Blank
to understand this particular syntax.
This is especially important for infix operators like this, because for some the F1 documentation search doesn't bring up a relevant page. Take the expression
x // f
or
f @ x
Running FullForm
on either of these returns f[x]
- telling you immediately what the notation means. This is good because if you highlight the @
or //
and hit F1 you will find Prefix
and Postfix
, which aren't very helpful for understanding what those symbols mean. But FullForm
will tell you how your syntax is interpreted by the front end, and what it is sent to the kernel as.
I'm not sure if this fully answers the question I posted, but after some more searching, I have discovered that it seems like _.
evaluates to Optional[]
, at least when using ReplaceAll[]
. An example will be better than words:
{_, _.} /. _Blank -> g
evaluates to:
{g, Optional[g]}
I know this is not a full answer, but hopefully it is at least partially helpful.