# Create a new infix operator

It is well known that the infix operator @@ is used as a short form of Apply.

For example, both Apply[f,{a,b,c}] and f@@{a,b,c} return f[a,b,c]}

Also the infix operator @@@ is used as a short form of Apply when it is used for levelspec {1}

For example, both Apply[f,{{a,b},{c,d}},{1}] and f@@@{{a,b},{c,d}} return {f[a,b],f[c,d]}

I would like to create a new infix operator named @@@@ (or other) to express Apply[f,expr,{2}] in a short form like f @@@@ expr.

Is it possible to create a new infix operator equivalent to some more verbose command ? Also which are the valid names I could use ?

-
it would be much simpler for you to use one of the several built-in infix operators that have no meaning (such as CirclePlus, CircleTimes...) –  rm -rf Jan 2 at 14:06
Thank you, you mean to define CirclePlus[f_, expr_] := Apply[f, expr, {2}]. Yes this solves my problem I saw in MMA's help there are CirclePlus, CircleMinus, CircleTimes and CircleDot. Also there are the OperatorsWithoutBuiltInMeanings that someone could use. Do you know If I could create my new one as a symbol combination ? –  tchronis Jan 2 at 14:30
I found this post : mathematica.stackexchange.com/questions/6355/… –  tchronis Jan 2 at 14:39
You can use any built in operator modified with subscripts, superscripts, etc, and retain its precedence, for your own purposes. Perpaps fro your case a @@ with a number subscripted for the level of Apply seems appropriate –  Rojo Jan 2 at 16:37
@Rojo Why don't you post that as an answer? –  Mr.Wizard Jan 2 at 18:11
show 1 more comment

You can use any built in operator modified with subscripts, superscripts, etc, and retain its precedence, for your own purposes. Perpaps fro your case a @@ with a number subscripted for the level of Apply seems appropriate

MakeExpression[RowBox[{fun_, SubscriptBox["@@", i_], rhs_}], StandardForm] :=
MakeExpression[{fun, rhs, i}, StandardForm] /.
HoldComplete /@ {f_, r_, level_} :>
HoldComplete@Apply[f, r, {level}]


To use it, you just type your usual @@ followed by the subscript hotkey (ctrl+- for example) and then the level of application.

Example, run

Cell[BoxData@RowBox[{"f",
SubscriptBox["@@", "1"],
RowBox[{"Nest", "[",
RowBox[{"List", ",", " ", "0", ",", "6"}], "]"}]}],
"Input"] // CellPrint


-
I like this a lot. I usually rely on the Notations package, but since I recently noted the overhead of that package I like the idea of a manual definition such as this. +1 :-) –  Mr.Wizard Jan 2 at 18:27
@Mr.Wizard I don't understand the Notation package too much (my fault, I never devoted enough time to that). As soon as I have time I'll look at your liked question. It seems interesting –  Rojo Jan 2 at 18:30
@Rojo thank you very much. Could you add an example just for clarity? –  tchronis Jan 2 at 19:09
@tchronis, humm, I am not sure it will add clarity :P –  Rojo Jan 2 at 19:19
Nice, +1! Could you give a small snapshot? –  ybeltukov Jan 2 at 19:25
No, unfortunately you cannot create a new compound operator such as @@@@, as stated by Michael Pilat in response to my own question of similar nature:
You can't do this with an operator syntax of your own invention (like @@&). Mathematica just doesn't have the capability to modify the language grammar at runtime like that.
There are a variety of methods you can use to effect new operators in the Front End but they are not actually extending the syntax of the language. Michael Pilat gives an example using the Notation Package in the referenced Q&A. More low-level you can modify the UnicodeCharacters.tr file as described in How is + as an infix operator associated with Plus? You could also use MakeBoxes, \$PreRead, or CellEvaluationFunction, but again none of these will work in Packages, so you are better off using built-in operators that are undefined.