[erlang-questions] Exceptions in guards are blocked. Why?

Alexander Semenov bohtvaroh@REDACTED
Fri Jan 30 13:00:55 CET 2009


Hi.

On Fri, 2009-01-30 at 11:56 +1300, Richard O'Keefe wrote:
> On 30 Jan 2009, at 2:14 am, Alexander Semenov wrote:
> 
> > Hi, folks,
> >
> > Can you explain me why exceptions are blocked in guards?
> 
> It is not that exceptions are *blocked* in guards,
> but that they signify *failure*.
> 
Nice point.

> > For example I wrote this in erlang shell:
> >
> > F = fun(X) when (X == 0) or (X / 0 > 2) -> true; (_) -> false end.
> 
> Why did you write that rather than
> 	F = fun (X) -> X == 0 orelse X/0 > 2 end
> 
I wrote this only as example, since Joe's book says, that such a guard
fails but nothing was said about what does it mean "fail". Thank you for
your explanation.

> > Is this cause of 'side effects free' guards nature?
> 
> Not really.  It's because guards aren't true or false;
> they succeed or fail.  (Blurring this distinction was a
> really bad idea.)
> 
-- 
Alexander Semenov <bohtvaroh@REDACTED>




More information about the erlang-questions mailing list