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

Ahmed Omar spawn.think@REDACTED
Fri Dec 2 10:38:28 CET 2011


Because "the guard expression must be guaranteed to be free of side
effects"
http://www.erlang.org/doc/reference_manual/expressions.html#id201090
So you are not allowed to have a function call there, except for allowed
BIFs that satisfy that condition


On Fri, Dec 2, 2011 at 10:30 AM, Barco You <barcojie@REDACTED> 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
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
Best Regards,
- Ahmed Omar
http://nl.linkedin.com/in/adiaa
Follow me on twitter
@spawn_think <http://twitter.com/#!/spawn_think>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111202/b0c48b1c/attachment.htm>


More information about the erlang-questions mailing list