|
It seems natural to me that the answer should be no, because this
evaluation can't change the result and it doesn't have any side effects by definition of guards. But while the reference manual (http://www.erlang.org/doc/reference_manual/expressions.html) explicitly says the rest of guards are not evaluated if one of them succeeds, it doesn't say whether guards fail fast. Yours, Alexey Romanov ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] |
|
Take a look at section 7.14 (Short-Circuit Expressions) as well as 7.24 of that chapter. It should clarify.
/s |
|
I've asked precisely because reading section 7.24 didn't clarify it
for me. The relevant sentences are "The guard is true if all guard expressions evaluate to true." and "If an arithmetic expression, a boolean expression, a short-circuit expression, or a call to a guard BIF fails (because of invalid arguments), the entire guard fails." The first sentence suggests to me that all expressions are evaluated; the second that expressions after the one that failed aren't. But both aren't explicit. I know about short-circuit expressions, but 7.14 doesn't say anything about evaluation of guards (unsurprisingly). Yours, Alexey Romanov On Sun, Feb 20, 2011 at 4:31 PM, Steve Davis <[hidden email]> wrote: > > Take a look at section 7.14 (Short-Circuit Expressions) as well as 7.24 of > that chapter. It should clarify. > > /s > > -- > View this message in context: http://erlang.2086793.n4.nabble.com/If-one-guard-expression-in-the-guard-fails-are-the-remaining-expressions-still-evaluated-tp3315062p3315110.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > ________________________________________________________________ > erlang-questions (at) erlang.org mailing list. > See http://www.erlang.org/faq.html > To unsubscribe; mailto:[hidden email] > > ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] |
|
The second sentance refers to the fact that if something in a guard throws an exception (i.e. fails) then the entire guard will fail. It does not refer to a guard statement returning false. If a guard statement does return false it will not continue executing if , are used, but it will of course do so if ; are used in the guard. You could of course skip the usage of , and ; and use andalso and orelse if you want control yourself of what will happen.
Lukas ----- Original Message ----- From: "Alexey Romanov" <[hidden email]> To: "Steve Davis" <[hidden email]> Cc: [hidden email] Sent: Sunday, February 20, 2011 3:46:27 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna Subject: Re: [erlang-questions] Re: If one guard expression in the guard fails, are the remaining expressions still evaluated? I've asked precisely because reading section 7.24 didn't clarify it for me. The relevant sentences are "The guard is true if all guard expressions evaluate to true." and "If an arithmetic expression, a boolean expression, a short-circuit expression, or a call to a guard BIF fails (because of invalid arguments), the entire guard fails." The first sentence suggests to me that all expressions are evaluated; the second that expressions after the one that failed aren't. But both aren't explicit. I know about short-circuit expressions, but 7.14 doesn't say anything about evaluation of guards (unsurprisingly). Yours, Alexey Romanov On Sun, Feb 20, 2011 at 4:31 PM, Steve Davis <[hidden email]> wrote: > > Take a look at section 7.14 (Short-Circuit Expressions) as well as 7.24 of > that chapter. It should clarify. > > /s > > -- > View this message in context: http://erlang.2086793.n4.nabble.com/If-one-guard-expression-in-the-guard-fails-are-the-remaining-expressions-still-evaluated-tp3315062p3315110.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > ________________________________________________________________ > erlang-questions (at) erlang.org mailing list. > See http://www.erlang.org/faq.html > To unsubscribe; mailto:[hidden email] > > ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] |
|
> If a guard statement does return false it will not continue executing if , are used
That's precisely what I was asking about. Thank you! Yours, Alexey Romanov > ----- Original Message ----- > From: "Alexey Romanov" <[hidden email]> > To: "Steve Davis" <[hidden email]> > Cc: [hidden email] > Sent: Sunday, February 20, 2011 3:46:27 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna > Subject: Re: [erlang-questions] Re: If one guard expression in the guard fails, are the remaining expressions still evaluated? > > I've asked precisely because reading section 7.24 didn't clarify it > for me. The relevant sentences are "The guard is true if all guard > expressions evaluate to true." and "If an arithmetic expression, a > boolean expression, a short-circuit expression, or a call to a guard > BIF fails (because of invalid arguments), the entire guard fails." The > first sentence suggests to me that all expressions are evaluated; the > second that expressions after the one that failed aren't. But both > aren't explicit. > > I know about short-circuit expressions, but 7.14 doesn't say anything > about evaluation of guards (unsurprisingly). > > Yours, Alexey Romanov > > > > On Sun, Feb 20, 2011 at 4:31 PM, Steve Davis > <[hidden email]> wrote: >> >> Take a look at section 7.14 (Short-Circuit Expressions) as well as 7.24 of >> that chapter. It should clarify. >> >> /s >> >> -- >> View this message in context: http://erlang.2086793.n4.nabble.com/If-one-guard-expression-in-the-guard-fails-are-the-remaining-expressions-still-evaluated-tp3315062p3315110.html >> Sent from the Erlang Questions mailing list archive at Nabble.com. >> >> ________________________________________________________________ >> erlang-questions (at) erlang.org mailing list. >> See http://www.erlang.org/faq.html >> To unsubscribe; mailto:[hidden email] >> >> > > ________________________________________________________________ > erlang-questions (at) erlang.org mailing list. > See http://www.erlang.org/faq.html > To unsubscribe; mailto:[hidden email] > > ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] |
| Powered by Nabble | Edit this page |
