-
-
Save abp/2049036 to your computer and use it in GitHub Desktop.
invoke a macro like a function
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
; 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