Because "the guard expression must be guaranteed to be free of side effects" <div><a href="http://www.erlang.org/doc/reference_manual/expressions.html#id201090">http://www.erlang.org/doc/reference_manual/expressions.html#id201090</a></div>
<div>So you are not allowed to have a function call there, except for allowed BIFs that satisfy that condition</div><div><br></div><div><br><div class="gmail_quote">On Fri, Dec 2, 2011 at 10:30 AM, Barco You <span dir="ltr"><<a href="mailto:barcojie@gmail.com">barcojie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Why does the following expression got "illegal guard expression" when compiling:<div>X = 0.5,</div><div>if</div>
<div>    random:uniform() < X ->      %error reported for this line</div><div>           good;</div>
<div>    true -></div><div>           bad</div><div>end.</div><div><br></div><div>But if I change it to following expression, it's ok:</div><div><div>X = 0.5,</div><div>Ran = random:uniform(),</div><div>if</div><div>

    Ran < X -> </div><div>           good;</div><div>    true -></div><div>           bad</div><div>end.</div></div><div><br></div><div>BRs,</div><div>Barco</div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Best Regards,<br>- Ahmed Omar<div><a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a></div><div>Follow me on twitter</div>
<div><a href="http://twitter.com/#!/spawn_think" target="_blank">@spawn_think</a></div><br>
</div>