On Fri, Mar 14, 2014 at 11:41 PM, Nathaniel Smith <njs@pobox.com> wrote:
Here's the main blocker for adding a matrix multiply operator '@' to Python: we need to decide what we think its precedence and associativity should be.

I am not ready to form my own opinion, but I hope the following will help shaping the discussion.

Currently, [1], Python operator precedence is

+- Addition and subtraction
*///% Multiplication, division, remainder [5]
+x-x~x Positive, negative, bitwise NOT
** Exponentiation [6]
x[index]x[index:index]x(arguments...)x.attribute Subscription, slicing, call, attribute reference

We need to decide whether @ belongs to one of the existing row or deserves one of its own.

The associativity debate is one of those debates [2] where there is no right answer.  Guido has very wisely left it for the numeric community to decide.  I would start with surveying the prior art of using right associativity and the reasons it was chosen and see if those reasons apply.  (An example of a choice made for wrong reasons is our decimal system.  We write our numbers backwards - from high to low place value - only because we took them from people who write text from right to left.  As a result, computer parsers have to skip to the last or count the number of digits before they can start evaluating the number.)

Here is the start:

1. APL uses right to left associativity for all operators and all operators have the same precedence.
2. Exponentiation operator is right associative in most languages with MATLAB being a notable exception.

[1] http://docs.python.org/3/reference/expressions.html#evaluation-order
[2] http://en.wikipedia.org/wiki/Lilliput_and_Blefuscu
[3] http://www.tcl.tk/cgi-bin/tct/tip/274.html