Re: Trying to rewrite a loop as map/reduce

2009-12-18 Thread Meikel Brandmeyer
Hi, Am 18.12.2009 um 04:18 schrieb Joseph Smith: > What are you using to generate the pretty rainbow perens on your website? I use Vim to do the highlighting. VimClojure does the rainbow parens. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Cl

Re: Trying to rewrite a loop as map/reduce

2009-12-17 Thread Joseph Smith
What are you using to generate the pretty rainbow perens on your website? --- Joseph Smith j...@uwcreations.com (402)601-5443 On Dec 17, 2009, at 5:25 PM, Meikel Brandmeyer wrote: > Hi, > > Am 16.12.2009 um 17:26 schrieb Meikel Brandmeyer: > >> Well. It was claimed it is cleaner... Just a

Re: Trying to rewrite a loop as map/reduce

2009-12-17 Thread Meikel Brandmeyer
Hi, Am 16.12.2009 um 17:26 schrieb Meikel Brandmeyer: > Well. It was claimed it is cleaner... Just asking... I wrote down my thoughts in a small blog post: http://tr.im/HW5P Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Re: Trying to rewrite a loop as map/reduce

2009-12-16 Thread Meikel Brandmeyer
Hi, On Dec 16, 4:30 pm, Laurent PETIT wrote: > Hey, the exercise was to rewrite it with higher order functions, not to make > it clearer ! Well. It was claimed it is cleaner... Just asking... Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Cloju

Re: Trying to rewrite a loop as map/reduce

2009-12-16 Thread Laurent PETIT
Hey, the exercise was to rewrite it with higher order functions, not to make it clearer ! 2009/12/16 Meikel Brandmeyer > Hi, > > On Dec 15, 10:28 pm, DTH wrote: > > > Damn, well played sir; that's much cleaner. > > Someone, please enlighten me! > > Why is this clearer? > > (defn foo > [a] > (

Re: Trying to rewrite a loop as map/reduce

2009-12-16 Thread DTH
On Dec 16, 8:13 am, Laurent PETIT wrote: > 2009/12/15 DTH > > > > (return-fn (some predicate-fn (iterate recur-fn a0))) > > > would seem equivalent, though I doubt I'd have got there without your > > stepwise guide to change the way I was thinking about it. > > No, some does not work here. Dean g

Re: Trying to rewrite a loop as map/reduce

2009-12-16 Thread Meikel Brandmeyer
Hi, On Dec 15, 10:28 pm, DTH wrote: > Damn, well played sir; that's much cleaner. Someone, please enlighten me! Why is this clearer? (defn foo [a] (let [b f1 c (comp f2 b) d (comp f3 c) e (comp f4 d) g (comp f5 c) h (comp f5 f2 e)] (->> (iterate

Re: Trying to rewrite a loop as map/reduce

2009-12-16 Thread Timothy Pratley
On Dec 16, 6:00 am, samppi wrote: > I'm trying to rewrite a loop to use higher-level functions instead. ;; Here is my 'novelty' answer... just for fun! [not a serious answer] ;; (defn bounce [start pred iter] (trampoline (fn f [x] (if (pred x) x (fn [] (f

Re: Trying to rewrite a loop as map/reduce

2009-12-16 Thread Laurent PETIT
Hello, 2009/12/15 DTH > On Dec 15, 9:05 pm, Laurent PETIT wrote: > > > > The final step is to apply return-fn to the result: > > (return-fn > > (first (remove > > (comp not predicate-fn) > > (iterate recur-fn a0))) > > > > Damn, well played sir; that's

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread DTH
On Dec 15, 9:05 pm, Laurent PETIT wrote: > > The final step is to apply return-fn to the result: > (return-fn >   (first (remove >                     (comp not predicate-fn) >                     (iterate recur-fn a0))) > Damn, well played sir; that's much cleaner. If I might offer one small tw

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread DTH
On Dec 15, 7:33 pm, Zach Tellman wrote: > At first glance I don't see a clean to make this completely higher- > order, but here's a shorter (albeit a little messy) version: > > (loop [a a0] >     (let [[a b c d e] (reduce #(conj %1 (%2 (last %1))) [a] [f1 f2 f3 > f4]) >           g (f5 c) >      

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread Meikel Brandmeyer
Hi, Am 15.12.2009 um 20:06 schrieb Sean Devlin: > Could you re-write this w/ comp, and repost? Because you need all intermediate results comp is totally useless here. (Unless you want to recompute everything several times, of course. But that might be prohobitive due to performance reasons...)

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread samppi
Wonderful. I'm still getting used to juggling functions like this, rather than doing standard loops. But it's so much cleaner. Thanks again, everyone; your explanations showed me not only how to solve my problem, but to organize my logic better too. On Dec 15, 2:32 pm, Laurent PETIT wrote: > Of

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread Laurent PETIT
Of course you're right. I couldn't remember filter, was somehow "stuck" with some which does not do the job of course, and playing with the doc did not help since my version of clojure still has the bug on filter's lack of documentation :-) 2009/12/15 Sean Devlin > On Dec 15, 4:05 pm, Laurent PE

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread Sean Devlin
On Dec 15, 4:05 pm, Laurent PETIT wrote: > Hello, > > it seems to me that your example is unnecessary complicated. > Let's refactor it a bit before trying to obtain your goal. > > First, > > your example can be, for the purpose of your goal, simplified as : > > (loop [a a0] >   (if (predicate-fn a

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread Laurent PETIT
Hello, it seems to me that your example is unnecessary complicated. Let's refactor it a bit before trying to obtain your goal. First, your example can be, for the purpose of your goal, simplified as : (loop [a a0] (if (predicate-fn a) (return-fn a) (recur (recur-fn a So now, what

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread Zach Tellman
At first glance I don't see a clean to make this completely higher- order, but here's a shorter (albeit a little messy) version: (loop [a a0] (let [[a b c d e] (reduce #(conj %1 (%2 (last %1))) [a] [f1 f2 f3 f4]) g (f5 c) h (-> e f2 f5)] (if (or (f6? b) (<= g h))

Re: Trying to rewrite a loop as map/reduce

2009-12-15 Thread Sean Devlin
Could you re-write this w/ comp, and repost? On Dec 15, 2:00 pm, samppi wrote: > I'm trying to rewrite a loop to use higher-level functions instead. > For pure functions f1, f2, f3, f4, f5, f6?, and f7, and a Clojure > object a0, how can one rewrite the following loop to use map, reduce, > etc.?

Trying to rewrite a loop as map/reduce

2009-12-15 Thread samppi
I'm trying to rewrite a loop to use higher-level functions instead. For pure functions f1, f2, f3, f4, f5, f6?, and f7, and a Clojure object a0, how can one rewrite the following loop to use map, reduce, etc.? (loop [a a0] (let [b (f1 a) c (f2 b) d (f3 c) e (f4