[erlang-bugs] lists:usort/2 documentation bug

Hans Bolinder <>
Tue Aug 19 08:30:41 CEST 2008


[Paul Mineiro:]
> the documentation says:
> 
> "Returns a list which contains the sorted elements of List1 where all but
> the first element of the elements comparing equal according to the
> ordering function Fun have been deleted. Fun(A, B) should return true if A
> comes before B in the ordering, false otherwise."
> 
> however, if one uses a fun that returns (A < B), one gets a bad result;
> this is because equality is detected via Fun (A, B) and Fun (B, A) both
> being true. so instead the fun should return (A =< B).  i would suggest
> rephrasing as
> 
> "... should return true if A compares less than or equal to B in the
> ordering, false otherwise".

Note that erlang:'<'/2 is not an ordering function (it is not reflexive).

This issue pops up every now and then, so I'll add a note stating what
is expected of an ordering function.

Best regards,

Hans Bolinder, Erlang/OTP team, Ericsson AB



More information about the erlang-bugs mailing list