Chris Angelico <ros...@gmail.com> writes: > Why is left-to-right inherently more logical than > multiplication-before-addition? Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything.
I'm a clearly a fool for allowing myself to be drawn into this thread, but I've been playing a lot recently with the APL-derivative language J, which uses a right-to-left operator precendence rule. Pragmatically, this is because J defines roughly a bajillion operators, and it would be impossible to remember the precendence of them all, but it makes sense in its own way. If you read "3 * 10 + 7", using right-to-left, you get "three times something". Then you read more and you get "three times (ten plus something)." And finally, you get "3*(10+7)". The prefix gives the continuation for the rest of the calculation; no matter what you substitute for X in "3*X", you will always just evaluate X, then multply it by 3. Likewise, for "3*10+X", no matter what X is, you know you'll add 10 and multiply by 3. This took me a while to get used to, but it's definitely a nice property. Not much to do with python, but I do like the syntax enough that I've implemented my own toy evaluator for J-like expressions in python, to get around the verbosity of some bits of numpy. Regards, Johann -- http://mail.python.org/mailman/listinfo/python-list