Skip to content

Instantly share code, notes, and snippets.

@rafaeldff
Created January 26, 2017 21:27
Show Gist options
  • Save rafaeldff/933557619064e990367dfc4dce7b765e to your computer and use it in GitHub Desktop.
Save rafaeldff/933557619064e990367dfc4dce7b765e to your computer and use it in GitHub Desktop.
lift macro to operate on functions
(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