Array of two empty sets asSet

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Array of two empty sets asSet

Janko Mivšek
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?

Best regards
Janko


--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si

Reply | Threaded
Open this post in threaded view
|

Re: Array of two empty sets asSet

Martin McClure-2
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.

Regards,

-Martin

Reply | Threaded
Open this post in threaded view
|

Re: Array of two empty sets asSet

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

Best regards
Janko

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
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si