How can I change the default grouping on an operator without a built-in meaning?

I've created my own infix operator by defining LeftArrow.

SetAttributes[LeftArrow, {NumericFunction, OneIdentity}]
ex1_ ← ex2_ := ex1 /. Rule[ex2[[1]], ex2[[2]]]

(I'm using the Esc<-Esc form of LeftArrow in the second line)

When I use it, I need to string together applications like so:

eqIld2 = (((((((eqIld ← eqVrx) ← eqVct) ← eqIcr) ← eqVct) ← eqIcl) ← eqVtx) ← eqIin)

I'd like to be able to avoid all the parentheses, and to get the same result for the same input with the parentheses removed.

I don't see the default grouping for LeftArrow documented anywhere. I've tried playing with various Attributes, but I can't find one that does what I want. It looks like there's an InfixNotation that accepts options, but they aren't documented.

What's the trick?



As it was correctly noted the Notation package is not necessary here and the key point is recursive definition which builds the desired ordering:

LeftArrow[x_,y_,z__] := LeftArrow[LeftArrow[x,y],z] ;

Notice that the z__ argument is followed by a double underscore, which allows the pattern to match an arbitrary number of arguments.

Original answer

Perhaps Notation package might help:

<< Notation` ;
f[x_,y_,z__] := f[f[x,y],z] ;
Notation[ParsedBoxWrapper[RowBox[{"x_", " ", "\[LeftArrow]", " ", "y_", " "}]] \[DoubleLongLeftRightArrow] ParsedBoxWrapper[RowBox[{" ", RowBox[{"f", "[", RowBox[{"x_", ",", "y_"}], "]"}]}]]] ;

then try:

a \[LeftArrow] b
a \[LeftArrow] b \[LeftArrow] c
a \[LeftArrow] b \[LeftArrow] c \[LeftArrow] d
a \[LeftArrow] b \[LeftArrow] c \[LeftArrow] d \[LeftArrow] e
  • 1
    $\begingroup$ Thanks! Turns out the Notation package isn't necessary. If I just add LeftArrow[ex1_, ex2_, ex3__] := LeftArrow[LeftArrow[ex1, ex2], ex3], it seems to do the trick. I'm new to Mathematica, and the recursive definition wasn't intuitive, but it's good to know that the more specific match is identified and made first. I think if you remove the reference to Notation, and add text to emphasize the double underscore on the z__ arg (which I overlooked for a while), then this is the answer I'm looking for. $\endgroup$ – Omegaman Aug 6 '15 at 19:40
  • $\begingroup$ Thanks for your feedback. You are right, Notation package is not needed here. I used it just because I had a similar problem and just copied my example with minor changes. $\endgroup$ – I.M. Aug 7 '15 at 2:51

If you don't mind mucking with the internal file UnicodeCharacters.tr (make a copy first!) you can change the line:

0x2190  ←   ($<-$ $&LeftArrow;$ $\leftarrow$ $\gets$)   Infix   380 None    5   5


0x2190  ←   ($<-$ $&LeftArrow;$ $\leftarrow$ $\gets$)   Infix   380 Left    5   5

and then close and relaunch Mathematica so that the changes take affect. Afterwards I get:

a ← b ← c //FullForm



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