<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 2 Dec 2011, at 10:38, Ahmed Omar wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">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></blockquote><div><br></div><div>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.</div><div><br></div><div>BR,</div><div>Ulf W</div><div><br></div><br><blockquote type="cite"><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>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote></div><br></body></html>