Lists:sublist oddity

Heinrich Venter heinrich@REDACTED
Mon Jan 30 10:16:28 CET 2006


I just discovered the following strange behaviour

32> lists:sublist([a,b,c],1,2).
[a,b]
33> lists:sublist([a,b,c],2,2).
[b,c]
34> lists:sublist([a,b,c],3,2).
[c]
35> lists:sublist([a,b,c],4,2).
[]
36> lists:sublist([a,b,c],5,2).
=ERROR REPORT==== 30-Jan-2006::10:59:47 ===
Error in process <0.72.0> with exit value:
{function_clause,[{lists,nthtail,[1,[
]]},{lists,sublist,3},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_
loop,3}]
}

** exited: {function_clause,[{lists,nthtail,[1,[]]},
                             {lists,sublist,3},
                             {erl_eval,do_apply,5},
                             {shell,exprs,6},
                             {shell,eval_loop,3}]} **

It would appear that sublist works according to the docs when
(Start-length(List1)) = 1 but fails when (Start-length(List1)) > 1

>From the source it would appear that the documentation is wrong :(
sublist WILL in fact fail if Start > length(List1)+1.

-]-[einrich



More information about the erlang-questions mailing list