<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 26, 2014 at 1:26 PM, Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>></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 class=""><div class="h5">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>>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's feasable to return an IdentitySet, other times it's not, so<br>
there's no optimal solution - #collect: can't cover all cases.<br>
<br>
Set >> #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>
"==> an IdentitySet(1 2 3 1.0 2.0 3.0)"<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] ==> 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] ==> 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's not a bug either. The Floats are not there, because they are equal to the integers:<br>
<br>
1 = 1.0 "==> true"<br>
1.0 = 1 "==> true"<br>
<br>
Therefore they have the same hash:<br>
<br>
1 hash "==> 1"<br>
1.0 hash "==> 1"<br>
<br>
The bug was in Squeak 2.8:<br>
1.0 = 1 "==> true"<br>
1 = 1.0 "==> true"<br>
1 hash "==> 1"<br>
1.0 hash "==> 61440"<br>
<br>
Here's the comment of Float >> hash from The Trunk:<br>
"Hash is reimplemented because = is implemented. Both words of the float are used. (The bitShift:'s ensure that the intermediate results do not become a large integer.) Care is taken to answer same hash as an equal Integer."<br></blockquote><div><br></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]) => 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)) => 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'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>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">best,<div>Eliot</div></div>
</div></div>