Re: Preferred order of evaluation

Jerry Leichter <leichter@smarts.com>
6 Sep 1996 22:27:55 -0400

          From comp.compilers

Related articles
Preferred order of evaluation fs29@rumpelkammer.uni-mannheim.de (Nils M. Holm) (1996-09-05)
Re: Preferred order of evaluation leichter@smarts.com (Jerry Leichter) (1996-09-06)
Re: Preferred order of evaluation dlmoore@ix.netcom.com (David L Moore) (1996-09-07)
Re: Preferred order of evaluation ok@cs.rmit.edu.au (1996-09-15)
Re: Preferred order of evaluation dmoen@mks.com (1996-09-15)
Re: Preferred order of evaluation gbcacm@ccs.neu.edu (1996-09-15)
| List of all articles for this month |
From: Jerry Leichter <leichter@smarts.com>
Newsgroups: comp.compilers
Date: 6 Sep 1996 22:27:55 -0400
Organization: System Management ARTS
References: 96-09-021
Keywords: design

Nils M. Holm wrote:
> 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?
>
> [It's one of those underwear questions, you like what you're used to.
> -John]


Traditional mathematical notation uses left-to-right evaluation for
operators of equal precedence. (It also only defines 3 or so levels of
precedence - addition, multiplication, exponentation, maybe unary
operators.)


Once you toss out *all* precedence, you've gotten away from traditional
notations.


I know of three programming languages that have discarded precedence,
and they've made both decisions about order of evaluation. As you
noted, APL uses straight right-to-left evaluation. The argument for it
is that, in reading an expression from left to right, you immediately
know what all the arguments are: What you just read is the left
argument, and the result of everything to the right is the right
argument. If you're going to have right-to-left assignment, and want to
treat assignment as an operator like any other (as APL does), right-to-
left evaluation is pretty much forced on you; otherwise, you'll have to
parenthesize the value being assigned in all but trivial cases. Also,
APL monadic functions act like prefix operators. With right-to-left
evaluation, you'd always need to parenthesize non-trivial arguments;
with right-to-left, F <expression> applies F to <expression>, which is
much more useful.


MUMPS (now known as M, I guess) uses straight left-to-right evaluation.
In M, assignment isn't an operator, so doesn't follow the left-to-right
rule. I've never seen an explanation for M's rule, but I'd guess it's
the same as the one for TECO, which also uses straight left-to-right
evaluation: Early (and most later) TECO interpreters interpreted the
source code directly, in a single left-to-right scan. It's unnatural to
do anything but left-to-right evaluation - which is what you're doing
for everything else in the language anyway - in this context.


-- Jerry
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.