[erlang-questions] How about a new warning? Was: Re: trouble with erlang or erlang is a ghetto

Richard Carlsson carlsson.richard@REDACTED
Wed Aug 3 18:17:39 CEST 2011


On 08/03/2011 05:05 PM, Thomas Lindgren wrote:
> I seem to recall that Mike Williams wanted a fully determined
> evaluation order long ago, for the Erlang spec. Was this implemented?

Yes. Arguments to functions and constructors are always evaluated 
left-to-right. This linearization is done in the transformation to Core 
Erlang, which doesn't in itself define an evaluation order for function 
arguments - the order from the Erlang source code is expressed on the 
Core level using let-bindings. (Run "erlc +to_core foo.erl" and look at 
the resulting file foo.core to see the explicit evaluation order.)

But I don't know if this rule has been formally documented anywhere 
after the work on the formal Erlang specification got indefinitely 
suspended. For reference, here's an old exchange between me, Robert, and 
Ulf:
http://erlang.org/pipermail/erlang-questions/2008-October/039170.html

(I also recall that Barklund had originally suggested that arguments of 
list constructors should be evaluated right-to-left as an exception, 
probably in order to reduce the number of temporaries needed while 
constructing a list like [f(), g(), h()], but this was voted down since 
it didn't make much sense to a human being reading the code.)

> And did it extend to pattern matching?

No, there was never any discussion about that. If the match succeeds 
then it would succeed no matter what the order, and if a you get a 
'badmatch' error, the entire matched term is blamed, not just the first 
subterm that doesn't match, so I can't see that there would be any 
observable difference depending on the order of matched subterms.

    /Richard



More information about the erlang-questions mailing list