Skip to main content
2 of 2
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/

The precedence of LongRightArrow is predetermined as shown in the operator table. You can attempt to circumvent the problem as other answers show but these do not change the binding power of the operator itself.

As you can see from the table Part has especially high binding power. What you want therefore goes against the design of Mathematica in some way; one would expect obj⟶(a[[1]]) rather than (obj⟶a)[[1]].

If you want to supersede Part you might consider something with natively higher binding power though there aren't many choices; Overscript is one:

Overscript[obj_, property_] := obj[ToString[property]];

Now entered using Ctrl+7:

enter image description here

Manually parenthesizing i.e. actually writing (obj⟶a)[[1]] is another option:

(obj⟶a)[[1]]
2

Note: you do not need to Unprotect Overscript or LongRightArrow as these operators are intended for use.

Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k