Created
January 26, 2017 21:27
-
-
Save rafaeldff/933557619064e990367dfc4dce7b765e to your computer and use it in GitHub Desktop.
lift macro to operate on functions
This file contains hidden or 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
(defmacro lift [n k] | |
(let [fns (gensym "fns") | |
args (gensym "args") | |
arity (int n)] | |
`(fn [& ~fns] | |
(fn [& ~args] | |
(~k ~@(for [i (range arity)] (list 'apply (list 'nth fns i) args))))))) | |
(def lor (lift 2 or)) | |
(def f (lor pos? (constantly 42))) | |
[(f 1) (f -1)] ; => [true 42] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment