[erlang-bugs] List comprehension generate "function clause" exception instead of "bad generator"

Ivan Glushkov <>
Fri May 11 15:59:12 CEST 2012


We have found recently an interesting behaviour:
- erlang console generate "bad generator" exception for the code:
1> [ {A,B} || {A,B} <- aaa ].
** exception error: bad generator aaa

- if compiled, the code throw "function clause" exception:

$ cat a.erl
a(List) -> [ {A,B} || {A,B} <- List ].

$ erl
1> c(a).
2> a:a(aaa).
** exception error: no function clause matching

The reason is that new anonymous function is created to handle the
list comprehension, but it expects only lists. So incorrect generator
also would cause a "function clause" exception.

I suppose that the reason of such an exception here is for the
similarity with the lists:map, it also generates a "function clause"
for unsupported arguments:

2> lists:map(fun(A) -> A end, aaa).
** exception error: no function clause matching

To my mind this behavior is not correct as somebody might expect "bad
generator" exception and he will try to catch it, but instead another
exception is thrown.


More information about the erlang-bugs mailing list