<!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">
If statement is not a block statement (to fix the variables values
at the entrance of the statement) in Erlang. That means, if an
uniform:random() value (say, 0.4) is used for checking the first
branch condition and the value is changed within the branch (say,
0.7), then you enter a paradox related to if the function should be
considered for the first or the second branch. To avoid this, Erlang
requires an assurance that the compared values do not change while
processing the if statement.<br>
<br>
CGS<br>
<br>
<br>
<br>
On 12/02/2011 10:56 AM, Barco You wrote:
<blockquote
cite="mid:CA+qFv3twC8kB5udUBjN-0GBf5kPzRTZb0oRC1H-vjO2q6U_M8g@mail.gmail.com"
type="cite">Hi CGS,
<div><br>
</div>
<div>I can't understand your statement --- " if in the first
branch you use again random:uniform(), the second branch
condition can report an inaccurate result." Could you please
make it clearer? Thanks!</div>
<div><br>
</div>
<div>Hi Others,</div>
<div><br>
</div>
<div>Why functions with side effect can not be in the guard
expressions?</div>
<div><br>
</div>
<div><br>
</div>
<div>Thank you!</div>
<div>Barco<br>
<br>
<div class="gmail_quote">
On Fri, Dec 2, 2011 at 5:50 PM, CGS <span dir="ltr"><<a
moz-do-not-send="true" href="mailto:cgsmcmlxxv@gmail.com">cgsmcmlxxv@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
<div 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
<div>
<div class="h5"><br>
<br>
<br>
<br>
On 12/02/2011 10:30 AM, Barco You wrote: </div>
</div>
<blockquote type="cite">
<div>
<div class="h5">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>
</div>
</div>
<pre><fieldset></fieldset>
_______________________________________________
erlang-questions mailing list
<a moz-do-not-send="true" href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a>
<a moz-do-not-send="true" href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</div>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a moz-do-not-send="true"
href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a moz-do-not-send="true"
href="http://erlang.org/mailman/listinfo/erlang-questions"
target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>