[erlang-questions] Order of evaluation of guards
Mon Jan 5 10:18:30 CET 2015
The main thing is ; is applied first, so your guard was like:
(( N > 0, M > 0, N < 100) ; (M < 100))
Then the whole single expression is evaluated.
> On 5 Jan 2015, at 09:04, Martin Koroudjiev <mrtndimitrov@REDACTED> wrote:
> Hi, thanks. So the "and" (,) is evaluated first and since (,) is not
> short circuit all will be replaced with true/false. And then the "or"
> will be evaluated.
>> On 1/5/2015 10:57 AM, Ivan Uemlianin wrote:
>> The last is correct according to your guards: M < 100. Perhaps you could try:
>> ... when N > 0, M > 0, N < 100;
>> N > 0, M > 0, M < 100 -> ...
>> Happy New Year!
>> festina lente
>>> On 5 Jan 2015, at 08:51, Martin Koroudjiev <mrtndimitrov@REDACTED> wrote:
>>> 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.
>>> (dilbert@REDACTED)2> F(1,2).
>>> (dilbert@REDACTED)3> F(1,200).
>>> (dilbert@REDACTED)4> F(0,200).
>>> (dilbert@REDACTED)5> F(0,50).
>>> The last is not correct.
>>> What is the order of evaluation of the guards? Sadly parentheses are not
>>> allowed in guards.
>>> Best regards,
>>> erlang-questions mailing list
More information about the erlang-questions