[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

left to right order of evaluation

    Date: Wed 21 Nov 84 15:52:49-EST
    From: Rodney A. Brooks <BROOKS%MIT-OZ at MIT-MC.ARPA>

    Is there any rational reason not to insist on left to right evaluation?

[People not interested in the answer to this question need read no further.]

I'll give you the reasons I can think of, and leave it to you to
determine their rationality.

1. There must be, since so many carefully designed languages (e.g.
BLISS, Algol 68, Scheme) and others as well (C, Pascal??, Modula??) make
a point of defining argument evaluation order to be indeterminate.

2. Defining the order of argument evalutation only encourages users to
write programs that make use of a particular order.  In the view of
certain pedagogues, such dependence is a stylistically horrible thing
which should be discouraged by the language design.  (In the view of
others, of course, it's just fine.)

3. While I agree that a compiler can do a lot in the way of detecting
cases where code motion is permissible, indeterminate order permits code
optimizations which no amount of compile-time analysis can prove
correct.  As a simple example, consider

        (BAR *X* (FOO))

Assume a machine model in which the two arguments are to be put in
registers A and B, and the return value from calls to unknown functions
comes back in A.  Left-to-right code for this would look like


*X* needs to be saved because the call to FOO, an unknown function,
might clobber it.  But better code would result if the call to FOO
happened first:


A compiler might like to generate code for the arguments which use the
largest number of registers (the "most complicated" arguments) first, in
order to reduce the amount of data shuffling the object code will have
to do.

4. A particular machine architecture and Lisp implementation might
prefer to evaluate right-to-left, e.g. so that arguments can be pushed
onto a stack properly.

I see now that Common Lisp is decidedly (if not definedly)
left-to-right, and that's probably the politically right thing.  Just
for the record, however, I'd like to say that I believe that a portable,
indeterminate order language can be made to work.