[erlang-questions] guard subexpressions resulting in a runtime error
7stud
7stud@REDACTED
Sun Jul 22 10:52:58 CEST 2012
$ erl -v
Erlang R15B01 (erts-5.9.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
According to "Erlang Programming" p.51,
"Guard subexpressions resulting in a runtime error are treated as returning false"
But with this function definition:
-module(t1).
-export([guard1/1]).
guard1(N) when ((N/0 == 0) or N==1) ->
hello.
I get the following runtime error:
$ erl
Erlang R15B01 (erts-5.9.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.1 (abort with ^G)
1> c(t1).
{ok,t1}
2> t1:guard1(1).
** exception error: no function clause matching t1:guard1(1) (t1.erl, line 4)
3>
I expected the guard subexpression (N/0 == 0) to generate a runtime error and therefore evaluate to false, and then (false or true) to evaluate to true, and therefore the atom 'hello' to be displayed.
More information about the erlang-questions
mailing list