title: How to implement a Lisp macro system?
body: <p>I've implemented my own Lisp on top of node.js, I can run s-expressions like this:</p>
  
  <pre>
  (assert (= 3 (+ 1 2)))
  
  (def even? (fn [n] (= 0 (bit-and n 1))))
  
  (assert (even? 4))
  (assert (= false (even? 5)))
  </pre>
  
  <p>Now I would like to add macros - the <code>defmacro</code> function - but this is where I'm stuck. I'm wondering how macro systems are implemented in other Lisps but I couldn't find many pointers (apart from <a href="http://www.reddit.com/comments/6ehu9/ask_reddit_tutorial_for_writing_a_lisp_interpreter" rel="nofollow noreferrer">this</a> and <a href="http://www.c2.com/cgi/wiki?LispMacro" rel="nofollow noreferrer">this</a>).</p>
  
  <p>I've looked at the Clojure macro system - the Lisp I'm most familiar with - but that seemed too complicated and I couldn't find additional clues that I can readily apply (Clojure macros ultimately compile to byte code which doesn't apply to javascript, also I couldn't make sense of the <code>macroexpand1</code> function.)</p>
  
  <p>So my question is: given a Lisp implementation without macros but with an AST, how does one add a macro system like Clojure's macro system? Can this macro system be implemented in Lisp, or does it require extra features in the implementation in the host language?</p>
  
  <p>One additional remark: I haven't implemented <code>quote</code> (<code>'</code>) yet because I couldn't figure out what kind of values should be in the returned list. Should it contain AST elements or objects like <code>Symbol</code> and <code>Keyword</code> (the latter being the case for Clojure)?</p>