# Operator precedence

## "Devon McCormick" <devon_mccormick@smb.com>17 Sep 1996 00:20:30 -0400

From comp.compilers

Related articles
Preferred order of evaluation fs29@rumpelkammer.uni-mannheim.de (Nils M. Holm) (1996-09-05)
Operator precedence devon_mccormick@smb.com (Devon McCormick) (1996-09-17)
| List of all articles for this month |

 From: "Devon McCormick" Newsgroups: comp.compilers Date: 17 Sep 1996 00:20:30 -0400 Organization: Compilers Central References: 96-09-021 Keywords: design

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]
>
> or
>
> 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
numbers.

I can find the citation of this if you are interested.
--
Devon McCormick
devon_mccormick@smb.com
--

Post a followup to this message