Created
March 17, 2012 08:50
-
-
Save kriyative/2056815 to your computer and use it in GitHub Desktop.
An alternate `defmacro2` definition with compile time semantics
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
(in-ns 'user) | |
;; An alternate `defmacro2` definition based on the example from | |
;; "Macros are Hard" presentation by @david_mcneil. This | |
;; implementation defines a macro called `name` and a function | |
;; equivalent called `name+` which still evaluates at compile time as | |
;; opposed to execution time | |
(defmacro defmacro2 [name args & body] | |
`(do | |
(defmacro ~name ~args ~@body) | |
(defn ~(symbol (str name "+")) [~@args] | |
(~name ~@args)))) | |
(defmacro2 foo [a b] `(+ ~a ~b)) | |
(foo+ 1 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment