5
$\begingroup$
 In[1] := Hold[a.b] // FullForm Out[1] := Hold[Dot[a,b]] 

So far so good.

 In[2] := Hold[a_.b_] // FullForm Out[2] := Hold[Times[Optional[Pattern[a,Blank[]]],Pattern[b,Blank[]]]] 

Why does the Dot become Times? I have a feeling it has something to do with the Optional that also appears, but I can't find anything that explains what's going on in the documentation.

$\endgroup$

1 Answer 1

8
$\begingroup$

See the documentation for Optional:

The special form s_. is equivalent to Optional[s_] and can be used to represent function arguments which, if omitted, should be replaced by default values globally specified for the functions in which they occur.

This explains the result your are receiving.

Thus, it seems you have a precedence problem, and a possible workaround is:

Hold[(a_).(b_)] // FullForm 

and get

Hold[Dot[Pattern[a, Blank[]], Pattern[b, Blank[]]] 
$\endgroup$
4
  • $\begingroup$ Even FullForm[Hold[(a_).b_]] is enough since now there are no special forms related to . in the expression. +1. $\endgroup$ Commented Jan 14, 2014 at 9:04
  • $\begingroup$ I have never seen an application of Optional... $\endgroup$ Commented Jan 14, 2014 at 10:31
  • $\begingroup$ Don't know how I missed that in the docs! Thanks. $\endgroup$ Commented Jan 14, 2014 at 16:51
  • $\begingroup$ A single space will also work: Hold[a_ .b_] // FullForm. @Murta Optional is quite useful. A few examples from my own answers: (17498), (20715), (29366), (30591), (30919), (47844), (51670). $\endgroup$ Commented Oct 25, 2014 at 1:37

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.