[erlang-questions] Core Erlang questions
Fri Oct 17 09:59:56 CEST 2008
Ulf Wiger wrote:
> 2008/10/16 Robert Virding <>:
>> There is a specific reason for the Erlang compiler to return code like that.
>> In Erlang the order of evaluation is defined to be left-to-right
> Where is this defined?
> I believe (too tired to check) that the Barklund spec left the
> evaluation order undefined, with the proviso that no possible
> evaluation order should leave variables unbound when used.
As far as I can remember, around the time when Barklund wrote that
spec it was decided that Erlang should have a fixed evaluation order,
so that there would never be a situation where a program would behave
slightly different (e.g., a process sending messages in a different
order, or a different exception being thrown) on an alternative
implementation. I think some minor things in the compiler were changed
at that time, to conform to the left-to-right principle. It does
restrict a bit what the compiler can do, though: only safe expressions
(free from side effects and exceptions) can be reordered at all.
I can't tell if this ever made it into any text, though.
In the core language, the evaluation order is made completely explicit,
as Robert explained, which forces the translated code to almost-normal
> In the Erlang Reference Manual, the only reference I found
> (during a very sloppy search) said that sub-expressions
> are evaluated in any order.
On one hand, that is not correct, given what I just described above.
On the other hand, it's probably best if programmers never get into
the habit of treating the evaluation order as known. So if you read
the above, please forget it again for your everyday work.
More information about the erlang-questions