## Support of algebraic operations on sets

Gary Chambers gazzaguru2 at btinternet.com
Fri Jun 15 14:49:05 UTC 2007

```Indeed. Need to decide if keys are enough or association pairs are
necessary.
Personally, I'd take keys.

-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of sig
Sent: 15 June 2007 3:43 pm
To: The general-purpose Squeak developers list
Subject: Re: Support of algebraic operations on sets

On 15/06/07, Bert Freudenberg <bert at freudenbergs.de> wrote:
>
> On Jun 15, 2007, at 14:45 , sig wrote:
>
> > actually i missing these operations for dictionaries.
> > in current implementation if you diff/union on two dictionaries,
> > you'll find out that associations play role as set elements, not
> > keys.
> >
> > for dictionaries 'a difference: b' i get not exactly what i would
> > expect.
>
> Dictionaries are like other collections - a collection of "elements"
> (the values). The keys are only interesting for accessing
> - like indices on Arrays.  #do: operates on the values. So does
> #select:, and #difference:. You wouldn't expect #difference: on an
> Array to work on its indices, would you?
>
Consider following example (union of two dictionaries):

| dict1 dict2 result1 result2 |
dict1 := Dictionary new.
dict2 := Dictionary new.
dict1 at: 1 put: 5.
dict2 at: 1 put: 6.

result1 := dict1 union: dict2.
result2 := dict2 union: dict1.

union defined as commutative operation fails in this example, because
result1<>result2. it can be considered as commutative only in case if we
taking resulting keys into account, not values. from this point same logics
must be followed when doing intersection/difference for dictionaries - take
only keys into account, not their associative values.

So, i'd expect 'dict1 difference: dict2'  must return empty dictionary, as
well as dict1 intersection: dict2  return non-empty dictionary.

Btw, all this is based on wrong semantics of Association '=' mehod, which
compares not only keys, but values also. This was discussed in other topic
before.

```