[erlang-questions] lists:seq/3 strange behaviour

Jesper Pettersson <>
Tue Jun 8 15:58:07 CEST 2010


Piotr wrote:
> What was the reason for lists:seq function to be implemented in a way that
if you call:
> lists:seq(2, 1, 10)
> it works as expected returning an an empty list, while when beeing called
like:
> lists:seq(20, 1, 10)
> it throws an exception?

Pascal wrote:
> Or, a solution that I prefer, add a default condition which return an
empty list as you suggest.

In earlier versions (for example R12B-5) lists:seq/3 on the examples above
throws a function-clause exception which makes more sense than a missing
true-branch in an if-clause. I would prefer stronger guards and a
function-clause exception over a solution which returns an empty list simply
because the function is undefined for those cases.

/Jesper Pettersson


More information about the erlang-questions mailing list