[Prev][Next][Index][Thread]
Re: evaluation order
On Tue, 2 May 2000, P T Withington wrote:
> A friend asks why Dylan evaluates left-to-right, but for assignments first
> evaluates the right-hand side and then the left-hand side (obeying l-to-r
> within the sides).
>
> It seems logical to me that you compute the value before you compute where
> to put it, but he wonders if there is some deeper reason?
The last section of Chapter 4 of the DRM explains this. Any use of \:=
which corresponds to a function or function-macro call expands such that
the above really is l-to-r; i.e.:
foo.size := 4;
is equivalent to
size-setter(4, foo)
similarly for element-setter, aref-setter and "\xxx-setter" function
macros. (BTW, the order of execution of "size-setter" above, in relation
to the other parts of the left- and right-hand sides, is undefined.
You'd have to write intentionally obfuscated Dylan for that to matter,
though!) In these cases you aren't really "computing where to put it",
however.
The definition of \:= (Chapter 14) says that if the thing on the left-hand
side is a variable, it doesn't get "executed", so an "order of execution"
only exists for the right-hand side anyway.
HTH,
Hugh (doffing language-lawyer garb ...)
Follow-Ups:
References: