[erlang-questions] if and fun with erl

Taylor Venable taylor@REDACTED
Tue Feb 1 14:43:59 CET 2011

On Tue, Feb 1, 2011 at 08:28, Fernando Benavides
<fernando.benavides@REDACTED> wrote:
> If statements require a true clause. On your module you have one, on the
> console you don't.

A true clause is not strictly required; when evaluated, if no matching
branch of an "if" expression is found, an error occurs just like with

2> X = 3.
3> if X =:= 2 -> ok end.
** exception error: no true branch found when evaluating an if expression

In some (perhaps many) cases you may not even want a true branch, so
that invalid uses of the if expression cause an error, rather than
proceeding (for which you must then code defensively). That's part of
the "let it crash" philosophy.

Taylor C. Venable

More information about the erlang-questions mailing list