[erlang-questions] Order of evaluation of guards

Martin Koroudjiev mrtndimitrov@REDACTED
Mon Jan 5 09:58:48 CET 2015


Cool. Thanks. This works as expected:

G = fun(N, M) when (N > 0 andalso M > 0) andalso (N < 100 orelse M <
100) -> cool; (_, _) -> not_cool end.

On 1/5/2015 10:53 AM, Sergej Jurečko wrote:
>
> You can use paranthesis with andalso and orelse
>
> Sergej
>
> On Jan 5, 2015 9:51 AM, "Martin Koroudjiev" <mrtndimitrov@REDACTED
> <mailto:mrtndimitrov@REDACTED>> wrote:
>
>     Hello,
>
>     First of all - Happy New Year!
>
>     Suppose we have a function that accepts 2 integers and we want to
>     react
>     only when both integers are greater than 0 and one of them is less
>     than 100:
>
>     I tried:
>     (dilbert@REDACTED)1> F = fun(N, M) when N > 0, M > 0, N < 100; M
>     < 100
>     -> cool; (_, _) -> not_cool end.
>     #Fun<erl_eval.12.106461118 <tel:12.106461118>>
>     (dilbert@REDACTED)2> F(1,2).
>     cool
>     (dilbert@REDACTED)3> F(1,200).
>     cool
>     (dilbert@REDACTED)4> F(0,200).
>     not_cool
>     (dilbert@REDACTED)5> F(0,50).
>     cool
>
>     The last is not correct.
>     What is the order of evaluation of the guards? Sadly parentheses
>     are not
>     allowed in guards.
>
>     Best regards,
>     Martin
>
>     _______________________________________________
>     erlang-questions mailing list
>     erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>     http://erlang.org/mailman/listinfo/erlang-questions
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150105/24e76504/attachment.htm>


More information about the erlang-questions mailing list