[Pharo-project] Array of two empty sets asSet

Janko Mivšek janko.mivsek at eranova.si
Fri Nov 12 09:44:42 CET 2010

Thanks Martin for clarification. I simply forgot that normal sets work
based on equality, not identity. School-time mistake, I know .. :)

Best regards

On 11. 11. 2010 19:51, Martin McClure wrote:
> On 11/11/2010 06:44 AM, Janko Mivšek wrote:

>> What is rationale that
>> 	(Array with: Set new with: Set new ) asSet
>> returns only one set instead of two (as VW returns)? Those two new sets
>> are not identical, therefore asSet should return them both?
> They're not identical, but they are equal. It seems reasonable to
> consider two empty Sets equal to each other.
> Once you add a Set to another Set you can't add or remove anything from
> the inner Set anyway (because that would change the inner Set's hash,
> violating the invariant) so the two empty Sets might as well be the same
> Set, since they're effectively immutable once added to another Set.
> Unless you're *sure* that nothing will ever get added or removed from
> the inner Sets, you should use an IdentitySet for the outer set.
> Regards,
> -Martin

Janko Mivšek
Smalltalk Web Application Server

More information about the Pharo-project mailing list