check out clojure.core/comp, and it's source

2012/8/25 John Holland <jbholl...@gmail.com>

> This problem is really confusing me. I found a solution online, but I
> can't understand the solution. Can anyone explain to me why this
> works?
>
> The problem is stated as:
>
>
>
> Write a function which allows you to create function compositions. The
> parameter list should take a variable number of functions, and create
> a function applies them from right-to-left.
> (= [3 2 1] ((__ rest reverse) [1 2 3 4]))
> (= 5 ((__ (partial + 3) second) [1 2 3 4]))
>
>
> The examples would accept the solution replacing the ____.
>
> The solution I found is:
>
> (fn [x & xs]
>   (fn [& args]
>     ((fn step [[f & fs] a]
>        (if fs
>          (f (step fs a))
>          (apply f a)))
>      (cons x xs) args)))
>
>
> This works, and baffles me when I try to understand it.
>
> --
> 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
>

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