On Thu, 12 Mar 2009 12:45:00 -0700 (PDT)
Jason Wolfe <jawo...@berkeley.edu> wrote:
> > Also, union/difference/intersection/symmetric-diff are binary. Would
> > there be any interest in a patch to make them n-ary?
> >
> 
> Union, difference, and intersection are all variadic as of a month or
> so ago.  Are you on the latest SVN?
> 
> -Jason

Oops, so they are. I am actually on SVN but referred to (apparently)
out-of-date docs. That, or Rich has joined the circle of
time-machine-owning dynamic-language-designing BDFLs.

In that case, here's my two stabs at n-ary set symmetric difference:

  (defn symmetric-diff [& sets]
    (let [all-members (apply union sets)
          nr-memberships
            (fn [m] (apply + (for [s sets :when (contains? s m)] 1)))
          in-sym-diff (fn [m] (odd? (nr-memberships m)))]
      (set (filter in-sym-diff (seq all-members)))))

  (defn symmetric-diff
    ([s1] s1)
    ([s1 s2]
     (difference (union s1 s2)
                 (intersection s1 s2)))
    ([s1 s2 & sets]
     (reduce symmetric-diff s1 (conj sets s2))))

-Kyle

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to