Someone will have an elegant solution, but what comes to my mind is a
(somewhat) brute force "loop-recur" ... not not that much different from
what you suggested.  It would pass the "under construction" return lists to
itself and a dwindling amount ("rest") of the original list.  Add "first"
from the dwindling source list to the appropriate return list on each pass.
When the source/input list is empty, return the constructed lists.

Only one pass through the input list.  The loop-recur pattern looks like it
makes recursive function calls, but it's just iteration.

On Sat, Feb 27, 2010 at 8:54 PM, logan <duskli...@gmail.com> wrote:

> Let's say I want to write a function that takes as an argument a list
> of n numbers, and returns 4 lists, a list of odd numbers that are
> multiples of 5, a list of even numbers that are multiples of 5, a list
> of odd numbers that are not multiples of 5, and a list of even numbers
> that are not multiples of 5.
>
> If I were writing this function procedurally, I could create 4 empty
> lists, and iterate through my input list once, using a compound if
> statement to add to the appropriate list.
>
> In functional style, I could use filter, but I can't seem to think of
> a solution that doesn't end up iterating through the whole list
> multiple times.
>
> Can someone please teach me what is the correct clojure approach?
> Thanks.
>
> --
> 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<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=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