Re: need help eliminating ordinary recursion/thinking the Clojure way

2011-11-11 Thread Mike
Ahhh...excellent, I see why I was blind. =) If you just build your reduction collection in reverse, then the head of the reduction is always the one you want to compare with as you traverse the incoming collection. So you either cons one item or two onto the result, and when you're all done reve

Re: need help eliminating ordinary recursion/thinking the Clojure way

2011-11-11 Thread Michael Gardner
Since you're given a sorted list of intervals, you don't actually need to restart the whole merging process from the start after each merge; you can just replace the last interval in your output with the new, merged interval and continue from there. So `reduce' is the perfect tool for the job; m

need help eliminating ordinary recursion/thinking the Clojure way

2011-11-11 Thread Mike
I'm having a conceptual problem, thinking functionally, and I was hoping the fine Clojurians could take a peek. Boiled down, I need to do a combination of map and reduce on a collection. My "walker" needs to look at pairs along the collection, but then sort of "inject" new values and restart when