Set difference (or nearest approximation)

cdrick cdrick65 at gmail.com
Wed Dec 12 13:29:10 UTC 2007


just playing around:

(#(1 2 3) asSet) difference:  (#(1 2 3 4 5) asSet)                 a Set()
(#(1 2 3 9) asSet) intersection:  (#(1 2 3 4 5) asSet)           a Set(1 2
3)
(#(1 2 3 9) asSet) copyWithoutAll:  (#(1 2 3 4 5) asSet)      a Set(9)
(#(1 2 3 4 5) asSet) copyWithoutAll:  (#(1 2 3 9) asSet)      a Set(5 4)
(#(1 2 3 4 5) asSet) union:  (#(1 2 3 9) asSet)                    a Set(1 2
3 4 5 9)


I think you'dlike   aSet (4 5 9)

| set1 set2 difference |
set1 := #(1 2 3 9) asSet.
set2 := #(1 2 3 4 5) asSet.
difference := (set1 union: set2) copyWithoutAll: (set1 intersection: set2)


or
| set1 set2 difference |
set1 := #(1 2 3 9) asSet.
set2 := #(1 2 3 4 5) asSet.
difference := (set1 copyWithoutAll: set2) addAll: (set2 copyWithoutAll:
set1)


That's just a quick try...

Cédrick



2007/12/12, itsme213 <itsme213 at hotmail.com>:
>
> What collection type / message should I use for set difference? I can't
> seem
> to find any :-(
>
> Sophie
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20071212/f67f7232/attachment.htm


More information about the Squeak-dev mailing list