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

Jeff Schultz jws@REDACTED
Fri Aug 5 04:22:14 CEST 2011


On Wed, Aug 03, 2011 at 11:47:13PM +0200, Richard Carlsson wrote:
>> According to the Barklund spec (page 62), it said that "a compiler
>> must only accept a program if for any evaluation order, there will
>> not be an applied occurrence of an unbound variable".
>>
>> "For example, in a context where X is unbound, the expression (X=8) +
>> X should give a compile-time error."
>>
>> (And it does, too. I checked).

Thanks for pointing that out.  I'd have missed that one.

> An interesting twist on the example (X=8) + X is that if *both* arguments 
> create a binding of the same variable, as in:
>
>   (X=8) + (X=8)
>
> then Erlang will first evaluate the subexpressions, then *check* that the 
> results match so that a single agreed value of X can be exported out from 
> the whole expression, and only in that case will it call + on the results. 
> You can experiment with the following to see what I mean:

The difference between the two cases seems a bit weird to me.  I would
have expected that the meaning of a call f(Expr1, Expr2) (I'll write
it as |f(Expr1, Expr2)|) where the Expr are other Erlang expressions
should be exactly the same as

    |T1 = Expr1|,
    |T2 = Expr2|,
    f(T1, T2)

where the T are new variables and |.| is applied recursively.

In this case, |(X = 8) + X| means X = 8, T1 = X, T2 = X, T1 + T2,
which is okay, and |X + (X = 8)| means T1 = X, X = 8, T2 = X, T1 + T2,
which is a compile-time error.

While I appreciate the intent of Barklund's rule above, I don't think
it plays well with Erlang's explicit left-to-right order of
evaluation.


Erlang really could do with a concise, agreed, current specification,
preferrably executable.


    Jeff Schultz



More information about the erlang-questions mailing list