Re: Maps equality failure / Maps merge failure

Kostis Sagonas <[email protected]>
Newsgroups gmane.comp.lang.erlang.bugs
Message-ID <[email protected]>
On 03/24/2015 11:00 PM, Jesper Louis Andersen wrote:
> Erlang/OTP 17 [erts-6.3.1] [source-a1520d8] [64-bit] [smp:8:8]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V6.3.1  (abort with ^G)
> 1> L = [{-1,0},{0.0,0},{0,0},{1,0}].
> [{-1,0},{0.0,0},{0,0},{1,0}]
> 2> lists:sort(L).
> [{-1,0},{0.0,0},{0,0},{1,0}]
> 3> lists:sort(maps:to_list(maps:from_list(L))).
> [{-1,0},{0,0},{0.0,0},{1,0}]
> 4> v(2) =:= v(3).
> false
> 5> maps:to_list(maps:from_list(L)).
> [{-1,0},{0,0},{1,0},{0.0,0}]
>
> In other words, factoring L through a map makes the comparison and the
> sort go wrong.

The above may seem a bit weird at first but is not at all strange given 
that lists:sort/1 does not sort according to the (total) term order:

   Eshell V6.3.1  (abort with ^G)
   1> lists:sort([0, 0.0]).
   [0,0.0]
   2> lists:sort([0.0, 0]).
   [0.0,0]


and maps:to_list/1's manual page reads:

   to_list(Map) -> [{Key, Value}]

     Types:
       Map = #{}
       Key = Value = term()

   The fuction returns a list of pairs representing the key-value
   associations of Map, where the pairs, [{K1,V1}, ..., {Kn,Vn}], are
   returned in arbitrary order.


Kostis

PS. However, the manual has a typo: "fuction" should read "function" :)
_______________________________________________
erlang-bugs mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-bugs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.