<div dir="ltr">May I quote IRC on this one, if that can help…<div><br></div><div><div>21:53 < captain_fur>| in guards what is the difference between or/; and/,</div><div>21:54 < captain_fur>| what do people usually use, do they mean the same thing syntactically</div>
<div>21:54 < nox>| captain_furious: no</div><div>21:55 < nox>| ;, or and orelse are all different</div><div>21:55 < DeadZen>| and and and also andalso</div><div>21:55 -!- supertramp [~<a href="mailto:Alexander@www2nd.baz.cz">Alexander@www2nd.baz.cz</a>] has quit [Ping timeout: 245 seconds]</div>
<div>21:55 -!- hiyosi [~<a href="mailto:skip_it@50.17.30.125.dy.iij4u.or.jp">skip_it@50.17.30.125.dy.iij4u.or.jp</a>] has quit [Ping timeout: 264 seconds]</div><div>21:55 < nox>| captain_furious: "BadGuard; true", "true; BadGuard" and "true orelse BadGuard" will all succeed</div>
<div>21:56 < nox>| err</div><div>21:56 < darkthink>| :) @ DeadZen</div><div>21:56 < nox>| nah, that's right</div><div>21:56 < captain_fur>| i have only ever used ,/;/orelse andalso</div>
<div>21:56 < captain_fur>| never plain and/or</div><div>21:56 < nox>| then, "BadGuard orelse true", "BadGuard or true", "true or BadGuard" will all fail</div><div>21:56 < captain_fur>| i am doing a talk and so wondered what the difference was</div>
<div>21:56 < nox>| A; B is compiled to the following Core:</div><div>21:57 < nox>| (Core-like)</div><div>21:57 < nox>| "try A of true -> true; _ -> false catch _ -> false end orelse B"</div>
<div>21:57 < nox>| now you are confused because guards don't fail and no try are allowed in guards</div><div>21:58 < nox>| but they are allowed in Core guards, and guards *can* fail, the failures must just be silenced to false</div>
<div>21:58 -!- troutwine_away is now known as troutwine</div><div>21:58 -!- asabil [uid11150@gateway/web/<a href="http://irccloud.com/x-nkbqvyqukslcpbvg">irccloud.com/x-nkbqvyqukslcpbvg</a>] has joined #erlang</div><div>
22:00 < captain_fur>| hmmm ok</div>
<div>22:00 < nox>| so "length(X) =:= 3; true" succeeds for all X</div><div>22:00 < nox>| and "length(X) =:= 3 orelse true" doesn't</div><div>22:01 < captain_fur>| short circuit</div>
<div>22:01 < nox>| orelse shortcircuits too</div><div>22:01 -!- PavelSh [~<a href="mailto:pavelsh@89-65-185-173.dynamic.chello.pl">pavelsh@89-65-185-173.dynamic.chello.pl</a>] has joined #erlang</div><div>22:01 < nox>| but it doesn't shortcircuit the nonbooleanness or the crash of its first argument</div>
<div>22:01 < nox>| while ; does</div><div>22:02 < nox>| if X is not a list, the ; guard will succeeds anyway and the orelse one won't</div><div>22:03 < captain_fur>| ok</div></div><div>
<br></div></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><div><div><br></div><div>Cheers,</div><div>-- </div><div>Pierre Fenoll</div></div><div><br></div></div></div>
<br><br><div class="gmail_quote">On 19 May 2014 01:02, Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
On 18/05/2014, at 4:20 PM, Adel Zhang wrote:<br>
<br>
> hi, I am currently reading "learnyousomeerlang". In "Syntax in Functions" chapter "guards" section, Fred said<br>
><br>
> <quote><br>
> Note: I've compared , and ; in guards to the operators andalso and orelse. They're not exactly the same, though. The former pair will catch exceptions as they happen while the latter won't.<br>
<br>
<br>
</div>This is seriously misleading.<br>
<br>
The difference between X > Y , X < Z<br>
and X > Y andalso X < Z<br>
with respect to exceptions has NOTHING TO DO with whether<br>
it's comma or andalso. The right semantic model is that<br>
it is the tests X > Y and X < Z themselves which change.<br>
If a guard test would have raised an exception, that<br>
turns into a simple failure of the guard test.<br>
<br>
Example:<br>
<br>
1> F1 = fun (X) when X+1 > 2 -> ok ; (_) -> oops end.<br>
2> F2 = fun (X) -> B = (X + 1 > 2), if B -> ok ; true -> oops end end.<br>
3> F1(snark).<br>
oops<br>
4> F2(snark).<br>
** exited: {badarith,...} **<br>
<br>
This being so, "," never gets to *see* an exception,<br>
so how could it catch one?<br>
<br>
You can't verify Fred's statement, because it isn't true.<br>
"," and ";" no more catch exceptions than "->" does.<br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div>