<div dir="ltr"><div><div>That the ',' is not short circuit is an implementation detail, and the wrong choice at that. Originally guards were evaluated from left-to-right and as soon as a test failed the guard failed, the ',' was short circuiting. This was also consistent with ';' alternate guards which was also left-to-right and short-circuiting, as soon as one of the guard sequences succeeded the whole guard succeeded.<br><br></div>I don't know when ',' became strict but it was never intended to be that. It should behave the same as 'andalso' and not as 'and'.<br><br></div><div>Note that there is one very significant difference between ';' and or/orelse and that is how they behave with errors. ';' will just fail that one guard sequence and attempt the next one while or/orelse will fail the guard sequence they are in. So if they are used as an alternative to ';' you will get different behaviour.<br><br></div><div>That errors in guards cause the guard to fail and not generate an exception was an intentional design decision, it saved a lot of explicit type tests and they were implicit in the operations. For example you could do tuple_size(T) without first having to check if T is a tuple.<br><br></div><div>Robert<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 5 January 2015 at 12:36, Jesper Louis Andersen <span dir="ltr"><<a href="mailto:jesper.louis.andersen@gmail.com" target="_blank">jesper.louis.andersen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br><br><div>Guard order don't matter! You are limited to a small set of expressions and BIFs in guards. All of these are guaranteed to be total in the sense that either producing a result or terminating. By not defining a rule for guard order, the compiler is free to reorder guard expressions as it sees fit. It can also cache results of guard expressions, since they won't change during the pattern match evaluation.</div><div class="HOEnZb"><div class="h5"><div><br></div><br><div class="gmail_quote">On Mon Jan 05 2015 at 10:18:37 AM Ivan Uemlianin <<a href="mailto:ivan@llaisdy.com" target="_blank">ivan@llaisdy.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The main thing is ; is applied first, so your guard was like:<br>
<br>
(( N > 0, M > 0, N < 100) ; (M < 100))<br>
<br>
Then the whole single expression is evaluated.<br>
<br>
Ivan<br>
<br>
--<br>
festina lente<br>
<br>
<br>
> On 5 Jan 2015, at 09:04, Martin Koroudjiev <<a href="mailto:mrtndimitrov@gmail.com" target="_blank">mrtndimitrov@gmail.com</a>> wrote:<br>
><br>
> Hi, thanks. So the "and" (,) is evaluated first and since (,) is not<br>
> short circuit  all will be replaced with true/false. And then the "or"<br>
> will be evaluated.<br>
><br>
><br>
>> On 1/5/2015 10:57 AM, Ivan Uemlianin wrote:<br>
>> The last is correct according to your guards: M < 100. Perhaps you could try:<br>
>><br>
>>  ... when N > 0, M > 0, N < 100;<br>
>>          N > 0, M > 0, M < 100 -> ...<br>
>><br>
>> Happy New Year!<br>
>><br>
>> Ivan<br>
>><br>
>> --<br>
>> festina lente<br>
>><br>
>><br>
>>> On 5 Jan 2015, at 08:51, Martin Koroudjiev <<a href="mailto:mrtndimitrov@gmail.com" target="_blank">mrtndimitrov@gmail.com</a>> wrote:<br>
>>><br>
>>> Hello,<br>
>>><br>
>>> First of all - Happy New Year!<br>
>>><br>
>>> Suppose we have a function that accepts 2 integers and we want to react<br>
>>> only when both integers are greater than 0 and one of them is less than 100:<br>
>>><br>
>>> I tried:<br>
>>> (dilbert@Martin-PC)1> F = fun(N, M) when N > 0, M > 0, N < 100; M < 100<br>
>>> -> cool; (_, _) -> not_cool end.<br>
>>> #Fun<erl_eval.12.106461118><br>
>>> (dilbert@Martin-PC)2> F(1,2).<br>
>>> cool<br>
>>> (dilbert@Martin-PC)3> F(1,200).<br>
>>> cool<br>
>>> (dilbert@Martin-PC)4> F(0,200).<br>
>>> not_cool<br>
>>> (dilbert@Martin-PC)5> F(0,50).<br>
>>> cool<br>
>>><br>
>>> The last is not correct.<br>
>>> What is the order of evaluation of the guards? Sadly parentheses are not<br>
>>> allowed in guards.<br>
>>><br>
>>> Best regards,<br>
>>> Martin<br>
>>><br>
>>> ______________________________<u></u>_________________<br>
>>> erlang-questions mailing list<br>
>>> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
>>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
><br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</blockquote></div>
</div></div><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>
<br></blockquote></div><br></div>