Wilson MacGyver a écrit :
> More newbie questions. :)
>
> If I have two sequences as follow:
>
> (2 3 4 5 6 7 8 9 10)
> (4 6 8 10)
>
> what's the best way to subtract the 2nd sequence from the first one?
>   

Is the order of the second sequence important? If not:
(defn subtract [a b]
  (remove (into #{} b) a)) ; turns b into a set for efficient 
(logarithmic) lookup
; user=> (subtract [2 3 4 5 6 7 8 9 10] [4 6 8 10])
; (2 3 5 7 9)

It works well as long as you don't have nil or false values in the 
second seq (in such cases you'll have to use 'contains?).

Christophe


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)



--~--~---------~--~----~------------~-------~--~----~
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