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...) > On Dec 15, 2:00 pm, samppi <rbysam...@gmail.com> 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.? >> >> (loop [a a0] >> (let [b (f1 a) >> c (f2 b) >> d (f3 c) >> e (f4 d) >> g (f5 c) >> h (-> e f2 f5)] >> (if (or (f6? b) (<= g h)) >> e >> (recur (f7 d b))))) I don't think, that higher-order functions make this clearer... Since you are only interested in the last step of the computation, this is calling for reduce. But reduce acts on a0. Not some inner condition for looping. Another approach might be define a lazy seq of the intermediate computation steps and calling last on it. I'm not sure, that this clarifies things. I would stick with loop/recur here. Sincerely Meikel -- 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