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)))
([x y z & args] (f (apply g x y z args)))))
([f g & fs]
(reduce1 comp (list* f g fs))))
Run Code Online (Sandbox Code Playgroud)
我是Clojure的新手并且试图了解它的技术方面和习惯风格方面,我想知道包含这么多情况的原因是什么,当两个函数被传入时comp.为什么要麻烦[xy]和[xyz]案件呢?