Those who don't have/prefer the front end of Mathematica will either use a plain ASCII editor to write a script in an .m file or just use Mathematica directly from a command-line terminal. In either case, everything must be supplied in InputForm.
When working with a Mathematica package, commonly used symbols/functions might be excessively verbose in InputForm, and certain shortcuts/aliases would be greatly desired. Examples of built-in InputForm shortcuts are the infix operators + (Plus), - (Minus), ... and . (Dot).
Two questions that arise as a package developer:
Can I make definitions to
InputForm? That is, can I modify how input supplied asInputFormgets parsed intoFullForm?
Example 1
<...> should correspond to AngleBracket. That is, should correspond to AngleBracket[a,b,c].
Example 2
Remap character . to package function myDot:
a.b.cshould be no longer be parsed inInputFormasDot[a,b,c]- It should be parsed
myDot[a,b,c].
(n.b. the solution for the analogous question in StandardForm assuming a front end is here.)
Answer
Unfortunately, I don't think there is. The association between characters and symbol names is burned into the kernel (in the form of a "yacc" grammar), with complete information about associativity, precedence, and tokenization.
Consider something as simple as your dot example. Presumably you want 2.3 to be the real number 2.3, not myDot[2,3]. How would you express that? In the box world you can redefine RowBox[{_,",",_}], but that's only because the FE has done the hardw ork for you of figuring out that 2.3 is boxed as "2.3", not as a RowBox[{"2",".","3"}]. The < > example is worse (and would be hard to do in an FE as well), because you're changing < and > from seaparate, binary operators to a matched pair.
Basically, the FE provides natural places to attach rules, which when all you have is a raw string is not an easy thing to do.
The best I can recommend is to find an operator without built in meaning, like say \[CenterDot], and attach definitions to the corresponding symbol. If you have a keyboard which has a center dot key (or shortcut) that's convinient for you, you can just use that. Otherwise, you'd have to type in \[CenterDot] each time, at which point you may as well be typing myDot[...].
Comments
Post a Comment