Re: [S] Unusual result

Berwin Turlach (
Wed, 25 Mar 1998 22:09:36 +1100

G'day Matt,

>>>>> "MW" == Matt Calder <> writes:

MW> S-news, I came across this today and was surprised by the
MW> result. Perhaps someone could explain this in terms of order of
MW> operations.

MW> After: a <- 0
MW> a <- (a <- a + 1) + (a <- a + 1)

MW> The value of a is 4. I expected 3.
Well, I cannot explain it in terms of order of operations. My guess
is, that this sequence of instruction eventually boils down to the
execution of the following instructions:
1) fetch `a', add 1 to it and store it in `a' [first a<-a+1, now a=1]
2) fetch `a', add 1 to it and store it in `a' [second a<-a+1, now a=2]
3) to form the addition, we need the result of the code inside the two
()'s, but that is stored in `a' [first ()] and `a' [second ()]. Hence,
fetch `a' and `a', add these two numbers and store the result in `a'.
Result: a=4.

It seems to be the S+ equivalent to i=i++ in C. You are probably
lucky that S+ didn't reformat your disk :)

Best wishes,


=============================== Full address ================================

Berwin A Turlach
Centre for Mathematics and its Applications Tel.: +61 (2) 6249 0706 (Secr.)
Statistical Science Program +61 (2) 6249 0731 (direct)
The Australian National University FAX : +61 (2) 6249 5549
Canberra ACT 0200 e-mail:
This message was distributed by To unsubscribe
send e-mail to with the BODY of the
message: unsubscribe s-news