On Wed, 11 Mar 2009 21:51:51 -0700 (PDT)
Raffael Cavallaro <[email protected]> wrote:
> On Mar 11, 11:43 pm, "Stephen C. Gilardi" <[email protected]> wrote:
>
> > Here are the expressions and results in a simplified notation:
> >
> > #{a b c} - #{a b} => #{c}
> >
> > #{a b} - #{a b c} => #{}
>
> ok, so I was misunderstanding how difference works. I thought both
> would evaluate to #{c}.
>
> thanks
clojure.set/difference implements the "relative complement" operation. I
don't see a "symmetric difference" operation in clojure.set, but it
might be useful:
(defn symmetric-diff
[xset yset]
(difference (union xset yset)
(intersection xset yset)))
It can also be implemented as the union of both relative complements:
(defn symmetric-diff
[xset yset]
(union (difference xset yset)
(difference yset xset)))
If you'd like to add it to the set library, I hereby release both
versions into the public domain.
Also, union/difference/intersection/symmetric-diff are binary. Would
there be any interest in a patch to make them n-ary?
-Kyle
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---