Hi,
Mike Fikes <[email protected]> wrote:
> In fact, section 5 of that document defines comp as a reduce
> involving the identify function in some way. (Now, I want to re-read
> this paper, but translated into Clojure.)
Here's one definition of comp in terms of reduce:
(defn comp [& fs]
(reduce (fn [result f]
(fn [& args]
(result (apply f args))))
identity
fs))
It's probably a bit clearer with one of the anonymous functions pulled
out and named:
(defn comp [& fs]
(letfn [(chain [result f]
(fn [& args]
(f (apply result args))))]
(reduce chain identity fs)))
They're less efficient than clojure.core/comp's implementation, but I
love the versatility of {reduce,fold,whatever}.
Best regards,
John
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.