[Pharo-project] Array of two empty sets asSet

Martin McClure martin at hand2mouse.com
Thu Nov 11 19:51:59 CET 2010

On 11/11/2010 06:44 AM, Janko Mivšek wrote:
> Hi guys,
> 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.



More information about the Pharo-project mailing list