I'm trying to understand how this function work, which is an implementation of comp (from the chapter "Functional Programming" in the book Clojure for the Brave and True):
(defn two-comp
[f g]
(fn [& args]
(f (apply g args))))
The idea is that it takes two functions and apply them to args. What I don't understand is how the args reach the anonymous function, since they are not entered as arguments to two-comp? How can be two-comp used this way?
gthat takes just one argument,(defn two-comp [f g] (fn [x] (f (g x))))returns a function that invokesfupon the result of invokinggupon its argument. As @mipadi explains, Thetwo-compin the question just modifies this so thatgcan have any number of arguments. - Thumbnail