On Wed, Jul 21, 2010 at 23:45, Travis Hoffman
<travis.a.hoff...@gmail.com> wrote:
...
> The second function is suggested as an addition to clojure.set. The
> "disjoint?" function decides if two sets have no elements in common.
> This can easily be done using:
>
>  (not (nil? (intersection s1 s2)))
>
> but this implementation should be more efficient (I think) and is more
> readable, imho:
>
> (defn disjoint?
>  "Is set1 disjoint from set2?"
>  {:added "1.3" :tag Boolean}
>  [set1 set2]
>  (if (<= (count set1) (count set2))
>    (recur set2 set1)
>    (not-any? (fn [item] (contains? item set1)) set2)))

so, when set1 and set2 are the same size, we recur, swapping the order
of the two arguments, which means set2 and set1 are the same size, so
we recur, swapping the two arguments, which means ...

  (if (< (count set1) (count set2))
    (recur set2 set1)
    ...)

would be better, no?

// ben

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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