Using gensyms is necessary to prevent variables produced by macro expansions
from interfering with user variables, and naming them mnemonically helps make
macro expansions and compiled code easier to read, but it's a pain to create
them properly. This macro creates them for you, which makes writing nice macros
easier. For example, if you are writing a macro to iterate over an array, you
used to have to write:
(defmacro do-2d-array ((elt array) &body body)
(let ((row (gensym ROW))
(col (gensym COL)))
(dotimes (,row (array-dimension 0))<br> (dotimes (,col ,(array-dimension 1))<br> (let ((,elt (aref ,array ,row ,col)))<br> . ,body)))))<br><br>Now you can just write the following, which eliminates the need to laboriously<br>create the mnemonic gensyms.<br><br> (defmacro do-2d-array ((elt array) &body body)<br> (with-variables (row col)<br>
(dotimes (,row ,(array-dimension 0))
(dotimes (,col ,(array-dimension 1))
(let ((,elt (aref ,array ,row ,col)))
. ,body))))