[erlang-questions] behavior of lists:append/1

Karlo Kuna kuna.prime@REDACTED
Sun Sep 15 19:44:38 CEST 2019


i have found surprising  behavior of function lists:append/1:

spec and documentation  are in a agreement that this function should accept
lists of lists ( [List] ) ,
and return list of T ( [T] ), however when we use function like:

     lists:append([a]) %wrong input parameter
one gets:
     a  % wrong type of a return

implementation assumes correct type:

append([E]) -> E; % E is not checked for type
append([H|T]) -> H ++ append(T);
append([]) -> [].

simple solution could be:

lists:append([E]) when is_list(E) -> E

am i missing something?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190915/11f061c8/attachment.htm>

More information about the erlang-questions mailing list