On Mar 7, 2009, at 6:44 PM, e wrote:

> check the discussion with the subject, "time lies, even with  
> doall".  We came up with something like the following, but some  
> name change change tweaks were suggested.  This thing takes a pred  
> and a collection and returns a list of two collections -- one that  
> passes the pred, and one that fails.
>
> (defn filt-rem [pred coll]
>    (loop [l1 () l2 () [f & r] coll]
>      (if f
>        (if (pred f)
>          (recur (conj l1 f) l2 r)
>          (recur l1 (conj l2 f) r))
>        (list l1 l2))))
>
>

This is almost identical to what I posted. However, is this the  
intended behavior?
(filt-rem identity '(true nil false 8)) => ((true) ())
(filt-split identity '(true nil false 8)) => [[true 8] [nil false]]

(filt-rem even? (range 10)) => ((8 6 4 2 0) (9 7 5 3 1))
(filter-split even? (range 10)) => [(0 2 4 6 8) (1 3 5 7 9)]

> (defn filter-split [pred coll]
>   (loop [trues '() falses '() coll coll]
>     (cond (empty? coll)
>           (vector (reverse trues) (reverse falses))
>           (pred (first coll))
>           (recur (cons (first coll) trues) falses (rest coll))
>           :else
>           (recur trues (cons (first coll) falses) (rest coll)))))

Aloha,
David Sletten


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