Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
Created December 8, 2012 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugoduncan/4241814 to your computer and use it in GitHub Desktop.
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
(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