[erlang-questions] illegal guard expression for IF illegal guard expression for "if"

Bengt Kleberg bengt.kleberg@REDACTED
Fri Dec 2 10:40:00 CET 2011


Greetings,

In 'if' you are only allowed guard expressions. They are here:
http://www.erlang.org/doc/reference_manual/expressions.html#id201090

(7.24  Guard Sequences)


bengt

On Fri, 2011-12-02 at 10:30 +0100, Barco You wrote:
> Why does the following expression got "illegal guard expression" when
> compiling:
> X = 0.5,
> if
>     random:uniform() < X ->      %error reported for this line
>            good;
>     true ->
>            bad
> end.
> 
> 
> But if I change it to following expression, it's ok:
> X = 0.5,
> Ran = random:uniform(),
> if
>     Ran < X -> 
>            good;
>     true ->
>            bad
> end.
> 
> 
> BRs,
> Barco




More information about the erlang-questions mailing list