Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created March 15, 2012 19:44
Show Gist options
  • Save alandipert/2046375 to your computer and use it in GitHub Desktop.
Save alandipert/2046375 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))
@fogus
Copy link

fogus commented Mar 15, 2012

This would be perfect for Evalive... ascii art and all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment