<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi all, <div class=""><br class=""></div><div class="">Consider the following inequalities:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2876> <<0,0,1>> < <<1,0,0>>.</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div></div><div class=""><br class=""></div><div class="">As well as:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2878> [0,0,1] < [1,0,0].</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div></div><div class=""><br class=""></div><div class="">The result (true) makes sense — in both cases operands are of the same size, and the first (leftmost) element value of the left operand is less than  first (again, leftmost) element value of the right operand.</div><div class=""><br class=""></div><div class="">However:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2877> <<0,0,1>> < <<1,0>>.   </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div></div><div class=""><br class=""></div><div class="">and</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2879> [0,0,1] < [1,0].  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div></div><div class=""><br class=""></div><div class="">This indicates that the actual length of the operands are not considered, for clearly, three octets cannot be less then two, right?</div><div class=""><br class=""></div><div class="">This becomes even more confusing if you check how tuples are compared given the similar test-case:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2886> {0,0,1} < {1,0,0}.  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2887> {0,0,1} < {1,0}.  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div></div><div class=""><br class=""></div><div class="">Here, the number of elements in the tuple are clearly taken into the consideration.</div><div class=""><br class=""></div><div class="">Then, if one converts all three pairs of operands to its (external) binary representation, e.g. </div><div class=""><br class=""></div><div class="">Binary:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2916> term_to_binary( <<0,0,1>> ).</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#ffffff" class=""><<131,109,</font><font color="#fffb00" class=""><b class="">0,0,0,</b><b class="">3</b></font><font color="#ffffff" class="">,0,0,1>></font></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2917> term_to_binary( <<1,0>> ).  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#ffffff" class=""><<131,109,</font><b class=""><font color="#fffb00" class="">0,0,0,2</font></b><font color="#ffffff" class="">,1,0>></font></span></div></div><div class=""><br class=""></div><div class="">List:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">tsdb_1_1@macbookv-3)2918> term_to_binary( [0,0,1] ).  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#ffffff" class=""><<131,107,</font><b class=""><font color="#fffb00" class="">0,3</font></b><font color="#ffffff" class="">,0,0,1>></font></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2919> term_to_binary( [1,0] ).  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#ffffff" class=""><<131,107,</font><b class=""><font color="#fffb00" class="">0,2</font></b><font color="#ffffff" class="">,1,0>></font></span></div></div><div class=""><br class=""></div><div class="">Tuple:</div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2920> term_to_binary( {0,0,1} ).</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#ffffff" class=""><<131,104,</font><b class=""><font color="#fffb00" class="">3</font></b><font color="#ffffff" class="">,97,0,97,0,97,1>></font></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2921> term_to_binary( {1,0} ).  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#ffffff" class=""><<131,104,</font><b class=""><font color="#fffb00" class="">2</font></b><font color="#ffffff" class="">,97,1,97,0>></font></span></div></div><div class=""><br class=""></div><div class="">One could see that the number of “elements” are known and available for comparison (I’ve highlighted this number using bold, yellow font) for all three situations.</div><div class=""><br class=""></div><div class="">And yet, the different approaches between binary and lists on one side, and tuples, on another, appear to be deliberate as binary and list types are following the approach used by C standard library memcmp function, whereas tuples do not, e.g.</div><div class=""><br class=""></div><div class=""><pre class=""><b class="">int memcmp(const void *</b><i class="">s1</i><b class="">, const void *</b><i class="">s2</i><b class="">, size_t </b><i class="">n</i><b class="">);</b></pre><pre class=""><font face="Helvetica" class="">In other words, operands are reduced to some common size ’<b class=""><i class="">n</i></b>', and then compared as if they were equal in length. </font></pre></div><div class="">I do understand this restriction in C -- if not for ’<b class=""><i class="">n</i></b>’, the argument sizes are not known, and without it the execution may end up in a catastrophic failure (e.g. segment violation, hmm.. which can still happen anyway if ’<b class=""><i class="">n</i></b>’ is inadequate).</div><div class=""><br class=""></div><div class="">So, THE QUESTION:</div><div class=""><br class=""></div><div class=""><i class="">Why would it be wrong to consider inequalities for binary() data types the same way we do it for tuples — number of “elements” first and  “numeric values” of individual elements — second?</i></div><div class=""><br class=""></div><div class="">In my view, this is not only <b class=""><i class="">not wrong</i></b>, but it would be more logical, and this is why.</div><div class=""><br class=""></div><div class="">Look at the following comparison:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2957> <<0,0,1>> < <<0,0,1,0>>.</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><br class=""></div></div><div class=""><br class=""></div><div class="">Well, this make sense, for less-is-less (e.g. three octets are less than four octets) and even if one considers  <<0,0,1>> as a 24-bit integer value, and <<0,0,1,0>> as a 32-bit integer, one may “normalise” the 24-bit integer to its 32-bit equivalent by adding a leading zero, and the comparison expression would still return true:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2961> <<0,0,0,1>> < <<0,0,1,0>>.   </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div></div><div class=""><br class=""></div><div class="">Therefore, as expected, 1 <  256, and, thus, we may be forgiven if we have the same expectation when we write:</div><div class=""><br class=""></div><div class=""><span style="color: rgb(255, 255, 255); font-family: Menlo; background-color: rgb(43, 102, 201);" class="">(tsdb_1_1@macbookv-3)2958> <<1>> < <<0,0,1,0>>.</span><span style="color: rgb(255, 255, 255); font-family: Menlo; background-color: rgb(43, 102, 201);" class=""> </span></div><div class=""> </div><div class="">Right? Well, not so, because:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2958> <<1>> < <<0,0,1,0>>.    </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div></div><div class=""><br class=""></div><div class="">Thus, "less is more", and therefore 1 appears to be greater-than-or-equal-to  256. Somehow.</div><div class=""> </div><div class="">This could never happen if one considered a number of elements (in this case number of octets) before attempting to compare the individual element values.</div><div class=""><br class=""></div><div class="">But wait, the "less-is-more" may easily become its opposite — “more is less”, because:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2973> <<32, 97>> < <<97>>.</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div></div><div class=""><br class=""></div><div class="">Yes, this approach may help us to sort a list of, say,  surnames alphabetically, so we can have all the “Ms” before the “Ns”, regardless of how long the surname is, but is this actually logical for two arbitrary binaries? Seeing that we actually care about number of elements when we deal with tuples, why not extend the same approach to arbitrary binary values?</div><div class=""><br class=""></div><div class="">Why do we presume that binaries are given as STRINGS when we compare them? When it comes to lists, the situation is even worse, because lists do, but then do not follow the STRING comparison semantic:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2991> [32, 97] < [97].  </span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">true</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(43, 102, 201);" class=""><b class=""><font color="#fffb00" class="">*** But! ***</font></b></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2992> [{32, 97}] < [97].</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(tsdb_1_1@macbookv-3)2993> [{32, 97}] < [{97}].</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(43, 102, 201);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div></div><div class=""><br class=""></div><div class="">And just to be clear, I do not expect Erlang to change. Nor do I care about how lists are handled (well, at least not for the moment).</div><div class=""><br class=""></div><div class="">My main concern is semantic behind comparing two arbitrary binary() operands. For one of my projects I’d like to employ tuple-like semantic (.e.g. number of octets first, values later) when comparing two arbitrary binaries and thus avoid “less-is-more” and “more-is-less” paradoxes.</div><div class=""><br class=""></div><div class="">Is there any reason why I shouldn’t? (Okay, it may be a bit slower, but one may argue this approach may be even a bit faster for a long-enough binaries. But what else?)</div><div class=""><br class=""></div><div class="">At any rate, I would appreciate your reasoning on the topic. What resonates better with you?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks in advance.</div><div class=""><br class=""></div><div class="">V/</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>