<div dir="ltr">2008/10/17 Richard Carlsson <span dir="ltr"><<a href="mailto:richardc@it.uu.se">richardc@it.uu.se</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Ulf Wiger wrote:<br>
> 2008/10/16 Robert Virding <<a href="mailto:rvirding@gmail.com">rvirding@gmail.com</a>>:<br>
>> There is a specific reason for the Erlang compiler to return code like that.<br>
>> In Erlang the order of evaluation is defined to be left-to-right<br>
><br>
> Where is this defined?<br>
><br>
> I believe (too tired to check) that the Barklund spec left the<br>
> evaluation order undefined, with the proviso that no possible<br>
> evaluation order should leave variables unbound when used.<br>
<br>
</div>As far as I can remember, around the time when Barklund wrote that<br>
spec it was decided that Erlang should have a fixed evaluation order,<br>
so that there would never be a situation where a program would behave<br>
slightly different (e.g., a process sending messages in a different<br>
order, or a different exception being thrown) on an alternative<br>
implementation. I think some minor things in the compiler were changed<br>
at that time, to conform to the left-to-right principle. It does<br>
restrict a bit what the compiler can do, though: only safe expressions<br>
(free from side effects and exceptions) can be reordered at all.<br>
</blockquote><div><br>Another reason to explicitly define evaluation order is that you also define where variables are visible and who binds them and who tests them. This can get *very* tricky in the general case. Fortunately people usually don't write that tricky and convoluted code. :-)<br>
<br>Robert<br><br></div></div></div>