Created
December 8, 2012 20:37
-
-
Save hugoduncan/4241814 to your computer and use it in GitHub Desktop.
Macros to call a function passed as an argument, where the function may be a macro
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
(defmacro mfn* | |
[[argv] body & args] | |
(let [[argv] args] | |
body)) | |
(defmacro mfn | |
"An macro form which looks like an anonymous function, and can be used to | |
inline a function call " | |
[args body & arg-vals] | |
`(let [~args ~(vec arg-vals)] | |
~body)) | |
(defmacro mapply | |
[f & args] | |
(if (and (sequential? f) (or (= `mfn (first f)) (= 'mfn (first f)))) | |
`~(concat f args) | |
`(~f ~@args))) | |
;; (mapply (mfn [x] x) 1) | |
;; (mapply (mfn [x] (+ x 2)) 1) | |
;; (mapply (fn [x] (+ x 3)) 1) | |
;; (mapply inc 1 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment