News for hackers. Stuff that matters.
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.

There are no comments on this comment yet.