<div dir="ltr">-module(guard).<br>-compile([export_all]).<br><br>test(X) when X == 0; 1/X > 2 -><br> true;<br>test(_) -><br> false.<br>6> c(guard). <br>{ok,guard}<br>7> guard:test(0). <br>true<br>
8> guard:test(0.4).<br>true<br>9> guard:test(0.6).<br>false<br>10> <br><br><br><div class="gmail_quote">On Sat, Jul 19, 2008 at 10:31 AM, Alpár Jüttner <<a href="mailto:alpar@cs.elte.hu">alpar@cs.elte.hu</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Btw. the Erlang Reference Manual says that<br>
<br>
As of Erlang 5.5/OTP R11B, short-circuit boolean expressions are<br>
allowed in guards. In guards, however, evaluation is always<br>
short-circuited since guard tests are known to be free of side<br>
effects.<br>
(Section 6.14, Short-Circuit Boolean Expressions)<br>
<br>
Something is wrong here, isn;t it?<br>
<br>
Regards,<br>
Alpar<br>
<div class="Ih2E3d"><br>
On Sat, 2008-07-19 at 06:50 -0700, Lev Walkin wrote:<br>
> Sean Allen wrote:<br>
> > by a small bit of example code in Programming Erlang related to guards<br>
> > and short circuit booleans:<br>
> ><br>
> > f(X) when (X == 0) or (1/X > 2) -><br>
> > ...<br>
> ><br>
> > g(X) when (X == 0) orelse ( 1/X > 2) -><br>
> > ...<br>
> ><br>
> > The guard in f(X) fails when X is zero but succeeds in g(X)<br>
> ><br>
> > Can someone explain why?<br>
><br>
><br>
> Sean,<br>
><br>
> The thing is, "or" does not short-circuit evaluation when left side<br>
> succeeds, whereas "orelse" does. Same short-circuit logic is<br>
> behind the differences between "and" and "andalso".<br>
><br>
> Actually, the very book you read explains these differences and warns<br>
> about caveats a couple pages later (or earlier). Don't stop reading.<br>
><br>
<br>
</div><div><div></div><div class="Wj3C7c">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a></div></div></blockquote></div><br><br clear="all"><br>-- <br>The great enemy of the truth is very often not the lie -- deliberate, contrived and dishonest, but the myth, persistent, persuasive, and unrealistic. Belief in myths allows the comfort of opinion without the discomfort of thought.<br>
John F. Kennedy 35th president of US 1961-1963 (1917 - 1963)
</div>