Clojure本身的core.clj代码(可在https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj获得)给出了以下定义comp:
(defn comp
"Takes a set of functions and returns a fn that is the composition
of those fns. The returned fn takes a variable number of args,
applies the rightmost of fns to the args, the next
fn (right-to-left) to the result, etc."
{:added "1.0"
:static true}
([] identity)
([f] f)
([f g]
(fn
([] (f (g)))
([x] (f (g x)))
([x y] (f (g x y)))
([x y z] (f (g x y z))) …Run Code Online (Sandbox Code Playgroud) clojure ×1