implementation of suffix

Robert Virding <>
Sun Jun 5 11:31:45 CEST 2005

I would say a bug, but in which clause is debatable.


Ulf Wiger (AL/EAB) wrote:

>The implementation of lists:suffix/2 is as follows:
>suffix(Suffix, Suffix) -> true;
>suffix(Suffix, [_|Tail]) ->
>    suffix(Suffix, Tail);
>suffix(_, []) -> false.
>The programming style in lists.erl seems to be to be very conservative
>about using type guards. One objection to this could be that it makes 
>it more difficult for Dialyzer to derive good type information from one of 
>the most frequently used modules, but in the case of suffix/2, I would
>say that it also violates the Principle of Least Astonishment:
>()13> lists:suffix(a,[1,2,3|a]).
>()14> lists:suffix(b,[1,2,3|a]).
>** exited: {function_clause,[{lists,suffix,[b,a]},
>                             {erl_eval,do_apply,5},
>                             {shell,exprs,6},
>                             {shell,eval_loop,3}]} **
>=ERROR REPORT==== 27-May-2005::15:36:23 ===
>Error in process <0.95.0> on node '' with exit value: {function_clause,[{lists,suffix,[b,a]},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
>Bug or feature?

More information about the erlang-questions mailing list