<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
Hi,<br>
<br>
To put in simple words for better understanding, you can have only
constant variables withing the guard expression. That means, in your
case, if in the first branch you use again random:uniform(), the
second branch condition can report an inaccurate result.<br>
<br>
Alternatively, you can use case statement:<br>
<br>
case (random:uniform()<0.5) of<br>
true -> good;<br>
false -> bad<br>
end<br>
<br>
I hope this answer will help you.<br>
<br>
CGS<br>
<br>
<br>
<br>
On 12/02/2011 10:30 AM, Barco You wrote:
<blockquote
cite="mid:CA+qFv3t9h5iT6ct_R5MnJB2smARcuvSbFyRL0nc_+h6bc+t99w@mail.gmail.com"
type="cite">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>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</body>
</html>