<div dir="ltr">Darren,<br><br>I am not sure I understand what is "not quite right". All I can see is that I didn't mention that a failed (as in, there was an exception or error) guard condition is treated as false.<br>
<br>I think your code works exactly as I would have expected. I see the sequence as:<br><br>First Clause:<br>f(0) when (0 == 0) [true] or ((1/X) > 2) [error = false] => entire guard fails, so try next clause.<br>Next Clause:<br>
f(0) when (0 == 0) true => short-circuit all subsequent guard conditions, so guard is true and clause is executed.<br><br>I was saying that the absence of side-effects in guard conditions allows Erlang to short-circuit  guard expressions of the format<br>
<br>   when cond1; cond2; cond3<br><br>or<br><br>   when cond1, cond2, cond3<br><br>This was not referring to use of or/orelse/and/andalso, which I tend to avoid in guards.<br><br>Please help me understand what you meant in your post.<br>
<br><div class="gmail_quote">On Sat, Jul 19, 2008 at 12:59 PM, Darren New <<a href="mailto:dnew@san.rr.com">dnew@san.rr.com</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;">
<div class="Ih2E3d">Edwin Fine wrote:<br>
> of guards, it is guaranteed that leaving out the evaluation of one or<br>
> more guards will not change the state of the program.<br>
<br>
</div>I don't think that's quite right.<br>
<div class="Ih2E3d"><br>
f(X) when (X == 0) or ((1 / X) > 2) -><br>
</div>   "does not return for zero X";<br>
f(X) when (X == 0) orelse ((1 / X) > 2) -><br>
   "does return for zero X".<br>
<br>
I might be misunderstanding here, but I understand that an "abrupt<br>
return" from a calculation in a guard is treated the same as "false".<br>
<br>
So in the first case, when X is 0, the guard evaluates to false, because<br>
1/X errors out, making the entire expression false.<br>
<br>
In the second case, 1/X isn't evaluated when X==0, making the entire<br>
expression true.<br>
<br>
It does seem like the documentation is wrong. I just tried the above<br>
fragment and it printed "does return" as its answer.<br>
<font color="#888888"><br>
--<br>
Darren New / San Diego, CA, USA (PST)<br>
  Helpful housekeeping hints:<br>
   Check your feather pillows for holes<br>
    before putting them in the washing machine.<br>
</font><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><br>
<br>
</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>