On Dec 15, 7:33 pm, Zach Tellman <ztell...@gmail.com> 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)
>           h (-> e f2 f5)]
>       (if (or (f6? b) (<= g h))
>         e
>         (recur (f7 d b)))))
>

While I, too, could not spot an obvious "completely" higher order
route, you can use `clojure.contrib.seq-utils/reductions` [1] to
cleanup the `reduce` in the above:

(require '[clojure.contrib.seq-utils :as s-u])

(let [f1-4 [f1 f2 f3 f4]]
  (loop [a a0]
    (let [[a b c d e] (s-u/reductions #(%2 %1) a f1-4)
          g (f5 c)
          h (-> e f2 f5)]
      (if (or (f6? b) (<= g h))
        e
        (recur (f7 d b))))))

-DTH

[1] 
http://richhickey.github.com/clojure-contrib/seq-utils-api.html#clojure.contrib.seq-utils/reductions

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