1
votes

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?

1

1 Answers

4
votes

You need to use ~ to unquote the symbol name:

(defmacro define [list & body]
  `(defn ~(first list) [~@(rest list)] ~@body))