[erlang-bugs] lists:usort bug 1
Hans Bolinder
hans.bolinder@REDACTED
Fri Jun 26 14:19:09 CEST 2009
[Lev Walkin:]
> usort(Fun, List1) -> List2
>
> Types Fun = fun(Elem1, Elem2) -> bool()
> Elem1 = Elem2 = term()
> List1 = List2 = [term()]
>
> 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.
>
> Actual behavior:
>
> 18> lists:usort(fun(A, B) -> A < B end, [a, a]).
> [a,a]
> 19> lists:usort(fun(A, B) -> A =< B end, [a, a]).
> [a]
> 20> lists:usort(fun(A, B) -> A >= B end, [a, a]).
> [a]
> 21> lists:usort(fun(A, B) -> A > B end, [a, a]).
> [a,a]
> 22>
>
> Contradicts description "should return true if A comes before B in the
> ordering, false otherwise".
Note that it is assumed by sort/2, usort/2, merge/3, and umerge/3 that
the fun is an "ordering function". Neither </2 nor >/2 is an ordering
function.
Best regards,
Hans Bolinder, Erlang/OTP team, Ericsson
More information about the erlang-bugs
mailing list