Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site rochester.UUCP
Path: utzoo!linus!philabs!cmcl2!seismo!rochester!quiroz
From: quiroz@rochester.UUCP (Cesar Quiroz)
Newsgroups: net.lang
Subject: Re: Reading programs left-to-right. (LONG)
Message-ID: <10984@rochester.UUCP>
Date: Sat, 10-Aug-85 23:24:00 EDT
Article-I.D.: rocheste.10984
Posted: Sat Aug 10 23:24:00 1985
Date-Received: Wed, 14-Aug-85 03:07:03 EDT
References: <6571@boring.UUCP>
Reply-To: quiroz@rochester.UUCP (Cesar Quiroz)
Organization: U. of Rochester, CS Dept.
Lines: 104

From article <6571@boring.UUCP> (jack@mcvax.UUCP (Jack Jansen)):
>
>Something that caught my attention a while ago is the following:
>
>Why do most programming languages do assignments like
>     
>
> ...
>
>1. The second case is simpler to produce good code for.
>   In the first case, the compiler should remember the 
>   expression, which may involve putting it on the stack or something
>   like that if the  is very complicated.

Not really relevant.  Given languages with sufficiently powerful lhs and rhs
expressions, either order will force the compiler to keep context.  Indeed,
this cannot be a heavy factor in any but the most restricted architectures
(Try run one such in an 8k machine and you may find the savings useful. Then
again, you may better not use other than assembler in that case.)  For
starters, which side is simpler in:

*x++ = *y++;  /* looks familiar? */

?

I feel more interested by your second point:
>2. (More important) The second case is much easier to read.
>   Everyone (well, almost everyone) reads and writes a program
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: quantifier used in risky context.  line above.  processing continues.
>   left-to-right:
>   ...
>

Recent postings seem to indicate that people split roughly in two schools
of opinion :  those who will give a try to any syntax, given that the human 
brain tends to accomodate very well to learning new notations, and those that
won't spend any time learning C because they already read Pascal.  I agree
that I would find easier to read a programming notation that were bidimensional
in its text, with the same preferred scan order orientation: left-to-right and
top-to-bottom.  But let me be afraid that no quantifier over the universe of
programmers will be left unchallenged by this network...  I myself enjoy 
jumping from C to Lisp and have been known for casual contacts with APL, FP
(and even COBOL!).  More below.
>I remember seeing a language with the second type assigments once,
>but it hasn't seemed to catch on.
>
>Does anyone know any good reasons for this?

I will bet that there are some historical reasons.  First, primitive parsers
were in desperate need for clean anchor points.  So, the significance of new
lines in Fortran.  Correspondingly, they wanted to be able to decide about
the statement type with little or no context.  This appeared in the form of
keywords or reserved symbols appearing as far to the left as was convenient.
As examples, BASIC's 'let' and FORTRAN's 'call' (or the mysterious commas,
mostly optional and normally forgotten, in 'do' and both the computed and the
assigned 'go to's).  (Anecdotally, I was once bitten by a compiler that wouldn't
take this:

      identifier
     *=  atrociously long Fortran expression

complaining that it couldn't identify the statement type on the basis of the
first card alone.)  Maybe somebody experienced with precedence or recursive-
descent only parsers can tell us if this "let me know soon" was really 
relevant in the early designs.

Your idea has interesting interactions with value-returning assignments.
For instance, good old UPL had 2 assignment operators: ":=" and "::=", called
"delete right" and "delete left" (though I no longer remember which is which).
One returned the final value stored in the left member ("delete right"), the
other kept around the value before conversions.  Let's assume that a language
is worked around your suggestion of left-to-right preference (which could mean
that the value "surviving" an assignment is the rightmost one), then we might
have "directional" assignments (say "->" and "<-"), with neat and wizardesque
consequences:

    float   x;
    int     i;
    f1 (int arg);
or
    f2 (float arg);

    /* assign value of i to x and call one of these functions */
    f1 (x<-i);  /* remember, i survives to be passed to f1 */
or
    f2 (i->x);  /* here we need a float, so we assign in the other order! */

reversing UPL's style (instead of always assigning right-to-left and deciding
which member is returned, we could always return the "last" member, and have
to decide on the direction of the assignment.)  In  this light, what does
everyone feel  about   x +=: y; /* add y to x, return old y */ or even the
canonical x :-) y ; /* do something to x and y and return whatever is needed */?

I'd like to see more of this subject being discussed.  (Even flames, not to
break old habits.)

Cesar
-- 
Cesar Augusto  Quiroz Gonzalez

Department of Computer Science     {allegra|seismo}!rochester!quiroz
University of Rochester            or
Rochester,  NY 14627               quiroz@ROCHESTER