title: Common Lisp unbound variable / defmacro
body: <p>I need to make the function defmacro for my meta-circular interpreter that can read this syntax:</p>
  
  <pre><code>pseudoscheme&gt; (defmacro (minus x y) (list ‘- y x))
  MINUS
  
  
  pseudoscheme&gt; (expand-macro '(minus 3 2))
  (- 3 2)
  </code></pre>
  
  <p>When I use this: </p>
  
  <pre><code>(defmacro my-defmacro ((name &amp;rest args) &amp;body  body)
      (let ((form (gensym))(env (gensym)))
          (progn 
          `(setf (macro-function ',name)    
              (lambda (,form ,env))
                  (destructuring-bind ,args (rest, form) ,@body))
          name
          )   
      )
  )
  </code></pre>
  
  <p>and then: </p>
  
  <pre><code>(my-defmacro (min a b)(list '- a b))
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Error: The variable MIN is unbound.
  </code></pre>
  
  <p>I can't understand why.</p>
  
  <p>-----EDITED-----
  If I use this:</p>
  
  <pre><code>(defmacro my-defmacro ((name &amp;rest args) &amp;body  body)
      (let ((form (gensym))(env (gensym)))
          `(progn (setf (macro-function ',name)
              (lambda (,form ,env))
                  (destructuring-bind ,args (rest, form) ,@body))
           ',name)    
      )
  )
  </code></pre>
  
  <p>and then: </p>
  
  <pre><code>(my-defmacro (min a b)(list '- a b))
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Error: Odd number of args to SETF: ((MACRO-FUNCTION (QUOTE PLUS)) (LAMBDA (#:G786 #:G787)) (DESTRUCTURING-BIND (A B) (REST #:G786) (LIST # A B)))
  </code></pre>