Reputation: 66650
I want to create scheme like define macro, here is my try:
(defmacro define [list & body]
`(defn ,(first list) [~@(rest list)] ~body))
but when I run:
(define (foo a b) (+ a b))
I've got error: java.lang.Exception: First argument to def must be a Symbol (NO_SOURCE_FILE:18)
what's wrong with my macro?
Upvotes: 1
Views: 76
Reputation: 144206
You need to use ~
to unquote the symbol name:
(defmacro define [list & body]
`(defn ~(first list) [~@(rest list)] ~@body))
Upvotes: 4