Skip to content

Instantly share code, notes, and snippets.

@abp
Forked from alandipert/macrofn.clj
Created March 16, 2012 07:54
Show Gist options
  • Save abp/2049036 to your computer and use it in GitHub Desktop.
Save abp/2049036 to your computer and use it in GitHub Desktop.
invoke a macro like a function
; Invoke a macro like a function - if you dare.
; ______
; .-" "-.
; / \
; _ | | _
; ( \ |, .-. .-. ,| / )
; > "=._ | )(__/ \__)( | _.=" <
; (_/"=._"=._ |/ /\ \| _.="_.="\_)
; "=._ (_ ^^ _)"_.="
; "=\__|IIIIII|__/="
; _.="| \IIIIII/ |"=._
; _ _.="_.="\ /"=._"=._ _
; ( \_.="_.=" `--------` "=._"=._/ )
; > _.=" "=._ <
; (_/ \_)
(defmacro ->fn [macro-name]
`(fn [& args#]
(-> @#'~macro-name
(vary-meta dissoc :macro)
(apply nil nil args#) ;nils are env and form
eval)))
(defmacro square [x]
`(let [x# ~x] (* x# x#)))
(map (->fn square) (range 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment