Binary, List and Tuple Inequalities (Paradox?)
Valentin Micic
v@REDACTED
Sun Nov 24 08:24:48 CET 2019
Thank you for jumping in. :-)
Am I alone in thinking that Barklund makes sense?
V/
> On 24 Nov 2019, at 01:51, Matthias Lang <matthias@REDACTED> wrote:
>
> Jumping into a thread that's a few weeks old.
>
> My first thought was to see what the 'Barklund' draft says:
>
> | An empty list precedes a cons ... and conses are ordered first by
> | their heads, then by their tails. (Thus a longer list may preced a
> | shorter list even though a shorter list tuple always precedes a
> | longer tuple.) For example, [] < [a|2] <[a|b] < [a] < [a, a], [b].
> |
> | http://www.erlang.org/download/erl_spec47.ps.gz
>
> So far no surprises, but then it says
>
> | Binaries are ordered first by their size, then according to their
> | elements lexicographically. (That is, the same as the order
> | between tuples of integers.
>
> So I think the Barklund draft doesn't agree with the implementation.
>
> I went back to OTP R8B. Even that doesn't agree with the Barklund draft:
>
> 1> init:script_id().
> {"OTP APN 181 01","R8B"} // I think R8B is from about 2002
> 2> <<0,0,1>> < <<1,0>>.
> true
>
> I'm not sure if the Barklund draft never agreed with the implementation,
> or if the implementation changed some time before 2003.
>
> Also, it seems that the current reference manual defines what happens
> for lists, but not binaries and bit strings:
>
> http://erlang.org/doc/reference_manual/expressions.html#term-comparisons
>
> Matthias
>
> ----------------------------------------------------------------------
> Date: 28. October 2019 From: Raimo Niskanen
> <raimo.niskanen@REDACTED> To erlang-questions@REDACTED Subject:
> Re: Binary, List and Tuple Inequalities (Paradox?)
>
>
>> I'd like to defend the current term order of lists, tuples and
>> binaries.
>>
>> Lists are compared a'la string comparison, which avoids having to
>> traverse the whole list when comparing. Binaries are compared as lists
>> since both are used for handling strings, and also to be compared like
>> memcmp does it.
>>
>> Tuples are used for general complex terms. They can be compared size
>> first whithout having to be fully traversed, as opposed to lists, which
>> is useful in other contexts. You can thereby choose your data
>> structure to select comparision.
>> --
>> Raimo Niskanen
>>
More information about the erlang-questions
mailing list