News for hackers. Stuff that matters.
Re:Partial Operator Precedence by kibwen on Thursday November 05, 2026 @09:00AM (#50379156)
I would like to see languages go even further. Make like Smalltalk did in 1972 and evaluate operators left-to-right with parentheses for grouping.
Re:Partial Operator Precedence by adrian_b on Thursday November 05, 2026 @09:06AM (#50379222)
In reality it is much better to evaluate all operators from right to left, as APL does since 1962 (with parentheses when you want another order).

Only in this direction the rule is always consistent, inclusively with assignment and with McCarthy logical operators.

Moreover, only with this evaluation direction the non-commutative operators lead to useful operations when applied to arrays.

In order to make evaluation from left to right always consistent, far more changes would have to be done to the syntax of a programming language, than with the APL evaluation rule.

Re:Partial Operator Precedence by kibwen on Thursday November 05, 2026 @10:03AM (#50379980)
There's no need to switch evaluation direction, as RPN and concatenative languages like Forth demonstrate.
Re:Partial Operator Precedence by adrian_b on Thursday November 05, 2026 @02:24PM (#50383250)
RPN and concatenative languages is what I meant when I said that for a consistent left-to-right evaluation you must make much more significant changes to the syntax of most programming languages (which are ALGOL-like) than with the APL evaluation rule.

You are right that RPN/concatenative languages is the alternative to the APL-like syntax, but they are even more distant from the traditional mathematical notation.

Re:Partial Operator Precedence by kibwen on Tuesday November 10, 2026 @05:44PM (#50447361)
Worth noting that I have no love whatsoever for traditional mathematical notation. We can do better.
Re:Partial Operator Precedence by childintime on Thursday November 05, 2026 @10:35AM (#50380435)
A procedural language is read top-down and left-to-right, so left-to-right is naturally favored. Without an example I don't get how right-to-left avoids the gotchas with non-commutative operators you hint at.
Re:Partial Operator Precedence by adrian_b on Thursday November 05, 2026 @02:37PM (#50383414)
In most programming languages, assignments are evaluated right-to-left, not left-to-right, which is in contradiction with the left-to-right evaluation used for most operators. The same is true for a few other syntactic forms.

The most frequently used non-commutative operators are subtraction and division.

With left-to-right evaluation, an expression like x1 - x2 - x3 - x4 means x1 - (x2 + x3 + x4), which is seldom a useful expression, but with right-to-left evaluation it becomes an alternating sum, i.e. what in left-to-right evaluation would be written as x1 - x2 + x3 - x4.

Given an array of numbers, it is very frequent to want their sum or their alternating sum, which can be obtained by applying "+" or "-" to it.

The same happens with division where dividing the first number by the product of the following is very seldom useful, but an alternating product, i.e. the product of the ratios of consecutive numbers, is frequently needed.

The same happens for other less common operators, the alternating operations are frequently useful.