Skip to content

Instantly share code, notes, and snippets.

@kriyative
Created March 17, 2012 08:50
Show Gist options
  • Save kriyative/2056815 to your computer and use it in GitHub Desktop.
Save kriyative/2056815 to your computer and use it in GitHub Desktop.
An alternate `defmacro2` definition with compile time semantics
(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