<div dir="ltr"><div><div>i would make an #identityCollect: for sets.</div></div><div class="gmail_extra">so it is more explicit, and also can be used with any other sets as input. <br><br></div><div class="gmail_extra"><div class="gmail_quote">On 26 November 2014 at 22:56, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Nov 26, 2014 at 1:26 PM, Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div>On Wed, 26 Nov 2014, David T. Lewis wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On Wed, Nov 26, 2014 at 08:01:49PM +0100, Levente Uzonyi wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On Wed, 26 Nov 2014, Eliot Miranda wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
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<br>
<br>
</blockquote>
<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<br>
<br>
</blockquote>
<br>
In Squeak 2.8 (checked on <a href="http://bertfreudenberg.github.io/SqueakJS/run/" target="_blank">http://bertfreudenberg.github.<u></u>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.<br>
</blockquote>
<br></div></div>
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;<br></blockquote><div><br></div></div></div><div>Exactly.</div><div><br></div><div>My hope would be something like this (Set order is arbitrary)</div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">        ((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><br></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">but that</span></div><div> <span style="color:rgb(80,0,80)">      (Set withAll: #(1 2 3 1.0 2.0 3.0)) =&gt; Set (1 2 3)</span></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">(and it always contains just the integers since these are added first).</span></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">But Levente&#39;s collect:as: solution is perfectly acceptable and as he points out has the advantage of being explicit.</span></div><div><span style="color:rgb(80,0,80)"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Levente<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Dave<br>
<br>
<br>
<br>
</blockquote>
<br><span class="HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>best,<div>Eliot</div></div>
</font></span></div></div>
<br><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Best regards,<br>Igor Stasenko.</div>
</div></div>