[S] unusual result

Luciano Molinari (molinari@kispi.unizh.ch)
Thu, 26 Mar 1998 11:17:57 +0100


Having been involved, many years ago, in the design of an ALGOL compiler, I
can't help giving my opinion on this issue.

If I recall correctly a statement such as
a+b (a and b could be expressions or functions)
would (should?) be translated to Polish notation as
ab+
and be evaluated as follows (strictly from left to right):

evaluate a, PUT RESULT ON TOP OF STACK, evaluate b, put result on top of
stack, add two top stack cells and replace them by result of addition.

For a statement such as
a+b+c (Polish notation ab+c+)
we would have:

evaluate a, put result on top of stack, evaluate b, put result on top of
stack, add two top stack cells and replace them by result of addition,
evaluate c, put result on top of stack, add two top stack cells and replace
them by result of addition.
If this is true then (P.Tukey's example)
S+>a_0
S+>print((a_a+10000)+ (a_a+1000))
should produce 21000 as a result.

Instead:
S+>a_0
S+>print((a_a+10000)+ (a_a+1000))
[1] 22000
which seems to imply that the evaluation proceeds as follows:
evaluate a, evaluate b (which also changes a), put a on top of stack, put b
on top of stack, add two top stack cells and replace them by result of addition.
I think this is deeply wrong, moreover partially inconsistent with the
following:
S+>a_0
S+>print((a_a+10000)+ (a_a+1000)+(a_a+100))
[1] 33100 (Left to right evaluation would give 32100)
which seems to imply that the evaluation proceeds as follows:
evaluate a, evaluate b (which also changes a),DO NOT YET EVALUATE C, put a
on top of stack, put b on top of stack, add two top stack cells and replace
them by result of addition, now evaluate c, put it on top of stack, add two
top stack cells and replace them by result of addition.

Notice also
S+>a_0
S+>print((a_a+10000)+ ((a_a+1000)+(a_a+100)))
[1] 33300
(Polish notation abc++, left to right evaluation 32100, again, as it should!)

L. Molinari

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news