assignment: left-to-right or right-to-left evaluation?

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Mon May 11 06:34:17 PDT 2009


Consider that mathematically speaking, an array is a function. And an
assignment to an array element actually changes the function.

A[i] = E;

is actually the same as

A = A[E/i];,

where the right-hand side reads: "A where i yields E" (notation not to be
confused with division). It is formally defined:

A[E/i][j] == E    (if i == j)
             A[j] (if i != j).

Of course, there are no side-effects in mathematics, but I believe it's
beneficial to try to keep as many well-known mathematical identities (like
that one) valid in the face of chaos.

So your first example would then be equivalent with

a = a[gun/fun];,

which still leaves the question of side-effect evaluation order. The second
example would read:

dic = dic[dic.length/word];,

which would suggest using the old dic.length.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list