Created
August 25, 2012 17:59
-
-
Save denlab/3468564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; you are starting here | |
(fn [x & xs] | |
(fn [& args] | |
((fn step [[f & fs] a] | |
(if fs | |
(f (step fs a)) | |
(apply f a))) | |
(cons x xs) args))) | |
;; name the fn | |
(defn mycomp | |
[x & xs] (fn [& args] | |
((fn step [[f & fs] a] | |
(if fs | |
(f (step fs a)) | |
(apply f a))) | |
(cons x xs) args))) | |
;; extract the step function | |
(defn step "Equivalent to (apply (comp f & fs) args)" | |
[[f & fs] args] (if fs | |
(f (step fs args)) | |
(apply f args))) | |
(defn mycomp "Equivalent to (partial step fns)" | |
[& fns] (fn [& args] | |
(step fns args))) | |
;; rename a few things for clarity | |
(defn comp-then-apply "Equivalent to (apply (comp f & fs) args)" | |
[[f & fs] args] (if fs | |
(f (comp-then-apply fs args)) | |
(apply f args))) | |
(defn mycomp "Equivalent to (partial comp-then-apply fns)" | |
[& fns] (fn [& args] | |
(comp-then-apply fns args))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment