# Functions in a different context are replaced with infix forms of their namesake in System

So, in an attempt to help out Fabian with his question, I did what I often do, and created a new symbol in the Pillsy package that I could play with. Since it was in a package I control completely, I thought, "Hey, I can just call it Times!". I was really surprised when this happened:

In[3]:= PillsyTimes[a, b, c]
Out[3]= a * b * c


It looks like Mathematica uses just the symbol name in determining whether to replace something with infix syntax, without paying attention to the context. However, I'm fairly sure I've never seen it happen before and I don't recall coming across it in the documentation. Evidently specifying InputForm shows you the whole thing:

In[4]:= PillsyTimes[a, b, c] // InputForm
Out[4]= PillsyTimes[a, b, c]


This is in contrast to the InputForm for SystemTimes.

Is this an intentional feature (it's hard to imagine otherwise), and if so, how does it interact with things like MakeBoxes, MakeExpression and Format?

Also, how do you avoid being burned by it? I'm a little alarmed that my assumption that a * b * c is the same thing as SystemTimes[a, b, c] is unfounded, even in the absence of changes to $Post and the like. - "help out halirutan with their question".. sorry, not my question ;-) – halirutan May 3 '12 at 17:32 @halirutan thanks for the fix! – Pillsy May 3 '12 at 17:51 ## 2 Answers It seems like the StandardForm (default for output) of Times in any context (or Plus, etc) is with the * and + symbols. But your assumption isn't wrong I think, the symbols * and + are mapped to System Times and System Plus. Try PrependTo[$ContextPath, "blo"];
bloTimes[a_, b_] := 8;

FullForm@MakeExpression[RowBox[{"a", "*", "b"}], StandardForm]


I think that this goes against Mathematica policy that "StandardForm generates output that gives a unique and unambiguous representation of Mathematica expressions, suitable for use as input"

-

The problem seems to be with ToBoxes:

Outer[#1[#2[a,b]]&,{ToString[#,OutputForm]&,ToBoxes},{Times,fooTimes}]
(*
==> {{"a b", "fooTimes[a, b]"}, {$$a\ b$$, $$a * b$$}}
*)


Note that Times and fooTimes are still different in that for Times, no * is generated.

When typing to the kernel directly, OutputForm is used, and fooTimes[a,b] gets printed:

In[1]:= {Times[a,b], fooTimes[a,b]}

Out[1]= {a b, fooTimes[a, b]}

-
If you try it with Plus` the + is generated for both –  Rojo May 3 '12 at 19:15