<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 26, 2014 at 2:37 PM, Frank Lesser <span dir="ltr">&lt;<a href="mailto:frank-lesser@lesser-software.com" target="_blank">frank-lesser@lesser-software.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<u></u>





<div lang="DE" link="blue" vlink="blue">

<div>

<p class="MsoNormal"><font color="navy" face="Arial"><span lang="EN-GB" style="font-size:10.0pt;font-family:Arial;color:navy">hmm, the problem is
different IMO,<u></u><u></u></span></font></p>

<p class="MsoNormal"><font color="navy" face="Arial"><span lang="EN-GB" style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>

<p class="MsoNormal"><font color="navy" face="Arial"><span lang="EN-GB" style="font-size:10.0pt;font-family:Arial;color:navy">**corrected, but still
wrong**<u></u><u></u></span></font></p>

<p class="MsoNormal"><font color="navy" face="Arial"><span lang="EN-GB" style="font-size:10.0pt;font-family:Arial;color:navy">(IdentitySet withAll: #(1
1.0)) collect: [:e| e asInteger ]   IdentitySet(1 )<u></u><u></u></span></font></p>

<p class="MsoNormal"><font color="navy" face="Arial"><span lang="EN-GB" style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>

<p class="MsoNormal"><font color="navy" face="Arial"><span lang="EN-GB" style="font-size:10.0pt;font-family:Arial;color:navy">collect: should always
preserve the size of the original collection so it must return an
OrderedCollection !</span></font></p></div></div></blockquote><div><br></div><div>Since when?  I&#39;m not sure I accept that collect: is one-to-one.  For Sets I wouldn&#39;t expect that.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="DE" link="blue" vlink="blue"><div><p class="MsoNormal"><font color="navy" face="Arial"><span lang="EN-GB" style="font-size:10.0pt;font-family:Arial;color:navy"><u></u><u></u></span></font></p>

<div>

<div class="MsoNormal" align="center" style="text-align:center"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">

<hr size="2" width="100%" align="center">

</span></font></div>

<p class="MsoNormal"><b><font face="Tahoma"><span style="font-size:10.0pt;font-family:Tahoma;font-weight:bold">Von:</span></font></b><font face="Tahoma"><span style="font-size:10.0pt;font-family:Tahoma">
<a href="mailto:squeak-dev-bounces@lists.squeakfoundation.org" target="_blank">squeak-dev-bounces@lists.squeakfoundation.org</a>
[mailto:<a href="mailto:squeak-dev-bounces@lists.squeakfoundation.org" target="_blank">squeak-dev-bounces@lists.squeakfoundation.org</a>] <b><span style="font-weight:bold">Im Auftrag von </span></b>Eliot Miranda<br>
<b><span style="font-weight:bold">Gesendet:</span></b> Mittwoch, 26. November
2014 22:57<br>
<b><span style="font-weight:bold">An:</span></b> <u></u>The
 general-purpose Squeak developers list<u></u><br>
<b><span style="font-weight:bold">Betreff:</span></b> Re: [squeak-dev]
IdentitySet&gt;&gt;collect:</span></font><u></u><u></u></p>

</div><div><div class="h5">

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">On Wed, Nov 26, 2014 at 1:26 PM, Levente Uzonyi &lt;<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>&gt; wrote:<u></u><u></u></span></font></p>

<div>

<div>

<p class="MsoNormal" style="margin-bottom:12.0pt"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">On Wed, 26 Nov 2014,
David T. Lewis wrote:<u></u><u></u></span></font></p>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">On Wed, Nov 26, 2014 at 08:01:49PM +0100, Levente Uzonyi wrote:<u></u><u></u></span></font></p>

<p class="MsoNormal" style="margin-bottom:12.0pt"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">On Wed, 26 Nov 2014,
Eliot Miranda wrote:<u></u><u></u></span></font></p>

<p class="MsoNormal" style="margin-bottom:12.0pt"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">Hi All,<br>
? ? IdentitySet&gt;&gt;collect: answers a Set, not an IdentitySet.? Anyone else<br>
agree this is a serious bug?? Anyone else disagree?<br>
<br>
WTF??<br>
<br>
(IdentitySet withAll: #(1 2 3 1.0 2.0 3.0)) collect: [:e| e] a Set(1.0 2 3)<br>
--<br>
best,Eliot<u></u><u></u></span></font></p>

<p class="MsoNormal" style="margin-bottom:12.0pt"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><br>
Sometimes it&#39;s feasable to return an IdentitySet, other times it&#39;s not, so<br>
there&#39;s no optimal solution - #collect: can&#39;t cover all cases.<br>
<br>
Set &gt;&gt; #collect: explicitly returns a Set, because this is the least bad<br>
solution to handle all of its subclasses reasonably well.<br>
In case of WeakSet, returning a WeakSet makes no sense, because some of<br>
your objects will disappear immediately.<br>
In case of IdentitySet, PluggableSet, KeyedSet and KeyedIdentitySet the<br>
returned values may not behave well in the original collection.<br>
<br>
The best is to always be explicit:<br>
<br>
(IdentitySet withAll: #(1 2 3 1.0 2.0 3.0)) collect: [ :e | e ] as:<br>
IdentitySet<br>
&quot;==&gt; an IdentitySet(1 2 3 1.0 2.0 3.0)&quot;<br>
<br>
Levente<u></u><u></u></span></font></p>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><br>
In Squeak 2.8 (checked on <a href="http://bertfreudenberg.github.io/SqueakJS/run/" target="_blank">http://bertfreudenberg.github.io/SqueakJS/run/</a>):<br>
<br>
 (IdentitySet withAll: #(1 2 3 1.0 2.0 3.0)) collect: [:e| e] ==&gt; a
Set(2.0 1 2 3 3.0 1.0)<br>
<br>
<br>
But in trunk I get this:<br>
<br>
 (IdentitySet withAll: #(1 2 3 1.0 2.0 3.0)) collect: [:e| e] ==&gt; a
Set(1 2 3)<br>
<br>
<br>
So answering a Set makes sense for the reasons that Levente explains, but trunk<br>
is definitely broken WRT the contents of that set.<br>
<br>
This bug needs a unit test to go along with whatever fix we agree on.<u></u><u></u></span></font></p>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

</div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">It&#39;s not a bug either. The Floats are not there, because they are equal
to the integers:<br>
<br>
1 = 1.0 &quot;==&gt; true&quot;<br>
1.0 = 1 &quot;==&gt; true&quot;<br>
<br>
Therefore they have the same hash:<br>
<br>
1 hash &quot;==&gt; 1&quot;<br>
1.0 hash &quot;==&gt; 1&quot;<br>
<br>
The bug was in Squeak 2.8:<br>
1.0 = 1 &quot;==&gt; true&quot;<br>
1 = 1.0 &quot;==&gt; true&quot;<br>
1 hash &quot;==&gt; 1&quot;<br>
1.0 hash &quot;==&gt; 61440&quot;<br>
<br>
Here&#39;s the comment of Float &gt;&gt; hash from The Trunk:<br>
        &quot;Hash is reimplemented because = is
implemented. Both words of the float are used. (The bitShift:&#39;s ensure that the
intermediate results do not become a large integer.) Care is taken to answer
same hash as an equal Integer.&quot;<u></u><u></u></span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">Exactly.<u></u><u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">My hope would be something like this (Set order is arbitrary)<u></u><u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" color="#500050" face="Times New Roman"><span style="font-size:12.0pt;color:#500050">       
((IdentitySet withAll: #(1 2 3 1.0 2.0 3.0)) collect: [:e| e]) =&gt;
IdentitySet (1 2 3 1.0 2.0 3.0)</span></font><u></u><u></u></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" color="#500050" face="Times New Roman"><span style="font-size:12.0pt;color:#500050">but that</span></font><u></u><u></u></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"> <font color="#500050"><span style="color:#500050">   
  (Set withAll: #(1 2 3 1.0 2.0 3.0)) =&gt; Set (1 2 3)</span></font><u></u><u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" color="#500050" face="Times New Roman"><span style="font-size:12.0pt;color:#500050">(and it always contains just the
integers since these are added first).</span></font><u></u><u></u></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<div>

<p class="MsoNormal"><font size="3" color="#500050" face="Times New Roman"><span style="font-size:12.0pt;color:#500050">But Levente&#39;s collect:as: solution is
perfectly acceptable and as he points out has the advantage of being explicit.</span></font><u></u><u></u></p>

</div>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">

<p class="MsoNormal" style="margin-bottom:12.0pt"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><br>
Levente<u></u><u></u></span></font></p>

<p class="MsoNormal" style="margin-bottom:12.0pt"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><br>
Dave<br>
<br>
<br>
<u></u><u></u></span></font></p>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</blockquote>

</div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><br>
<br clear="all">
<u></u><u></u></span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>

</div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">-- <u></u><u></u></span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">best,<u></u><u></u></span></font></p>

<div>

<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">Eliot<u></u><u></u></span></font></p>

</div>

</div>

</div>

</div>

</div></div></div>

</div>


<br><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">best,<div>Eliot</div></div>
</div></div>