More Shen macros today. In the previous post I promised an explanation for why we don’t have/need quasiquote, unquote and unquote-splicing in Shen. Let’s look at a Common Lisp example: a single place let. This would typically be written as: (defmacro let-one ((loc val) &rest body) `(let ((,loc ,val)) ,@body)) …using quasiquote, unquote and unquote-splicing. This is actually short hand for the following: (defmacro let-one ((loc val) &rest body) (append (list 'let (list (list loc val))) body)) I think everyone would agree that this second form is harder to read.
In this post I’m going to concentrate on Shen macros; some familiarity with basic Shen and Common Lisp macros is assumed. In Shen, as in traditional Lisp style, code is data and data is code. Shen code is read in as a list datastructure: (+ 1 2) becomes [+ 1 2]. Shen macros are functions that pattern match on the list representation of code at read time in order to rewrite it.