|Preferred order of evaluation email@example.com (Nils M. Holm) (1996-09-05)|
|Operator precedence firstname.lastname@example.org (Devon McCormick) (1996-09-17)|
|From:||"Devon McCormick" <email@example.com>|
|Date:||17 Sep 1996 00:20:30 -0400|
On 5 September 1996, Nils M. Holm asks:
> Given a language without any operator precedence, would you prefer
> 1) evaluation from the left to the right, like a sequence of identical
> Operations in C [a - b + c = (a - b) + c]
> 2) evaluation from the right to the left, like in APL?
> [a - b + c = a - (b + c)]
> What are the reasons for your choice?
There are 2 related reasons APL chooses right to left precedence:
1) the language supports the notion of applying a function across
an array, e.g. +/1 2 3 <-> 1 + 2 + 3, or (for infix function f)
f / 1 2 3 <-> 1 f 2 f 3;
2) for a non-commutative function, such as minus, the result is much
more interesting evaluated right to left, e.g. -/1 2 3 4 5
becomes the alternating sum (((1 - 2) + 3) - 4) + 5; if evaluation
were as in conventional mathematics, this would be equivalent
to the less interesting 1 - (2 + 3 + 4 + 5).
Similarly, division across a vector gives a continued fraction
instead of the first number divided by the product of the remaining
I can find the citation of this if you are interested.
Return to the
Search the comp.compilers archives again.