Field assignments are reordered in record creations
Romain Lenglet
rlenglet@REDACTED
Thu May 25 04:39:55 CEST 2006
David, thanks a lot fot this great explanation.
I expected the Erlang compiler to behave like a C compiler, and
to execute subexpressions with possible side-effects in the same
order as they are written...
> orbitz@REDACTED wrote:
> > So what is ,? Can I not depend on an expression prior to a
> > , being evaluated before something after the ,? What about ;
> > in guard statements? Is it the same idea, simply not called
> > a sequence point? Or is the idea not existent?
Yes, it is. In:
start() ->
format("foo"),
format("bar").
the two function calls are executed in the order in which they
are written, because "," in that case separates two expressions
and evaluates them in order.
Cf. section 6.5 in the ref cited by David Hopwood
(http://citeseer.ist.psu.edu/513634.html):
"The order in which the subexpressions of an expression are
evaluated is not defined, with one exception:
In a body, the expressions are evaluated strictly from left to
right."
So, using "," to separate expressions seems to be the only way to
have deterministic behaviour in Erlang.
--
Romain LENGLET
More information about the erlang-questions
mailing list