Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
 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.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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[]]]
share|improve this answer
    
Even FullForm[Hold[(a_).b_]] is enough since now there are no special forms related to . in the expression. +1. –  Kuba Jan 14 at 9:04
    
I have never seen an application of Optional... –  Murta Jan 14 at 10:31
    
Don't know how I missed that in the docs! Thanks. –  Dan Jan 14 at 16:51
    
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). –  Mr.Wizard Oct 25 at 1:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.