Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (in-ns 'user)
  2.  
  3. ;; An alternate `defmacro2` definition based on the example from
  4. ;; "Macros are Hard" presentation by @david_mcneil. This
  5. ;; implementation defines a macro called `name` and a function
  6. ;; equivalent called `name+` which still evaluates at compile time as
  7. ;; opposed to execution time
  8. (defmacro defmacro2 [name args & body]
  9.   `(do
  10.      (defmacro ~name ~args ~@body)
  11.  
  12.      (defn ~(symbol (str name "+")) [~@args]
  13.        (~name ~@args))))
  14.  
  15. (defmacro2 foo [a b] `(+ ~a ~b))
  16.  
  17. (foo+ 1 2)