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

Ulf Wiger ulf@REDACTED
Fri Dec 2 10:49:29 CET 2011


On 2 Dec 2011, at 10:38, Ahmed Omar wrote:

> 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

Yes, and not only does this mean that only a limited set of functions are allowed as guard functions, random:uniform() _does_ have side effects, since it updates the seed in the process dictionary.

BR,
Ulf W


> 
> 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
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111202/893b0808/attachment.htm>


More information about the erlang-questions mailing list