On Tue, May 3, 2011 at 3:37 AM, Peter Bex <[email protected]> wrote:

> This is a huge change in how macros behave.  Currently a macro can only
> expand into one form.  This is also why the splicing "inside" quasiquote
> is so weird.
>

quasiquote is still expanding into only one form -- the outer-most
quasiquote is doing all the work.

``,,(list 1 2) ==> (quasiquote (unquote 1 2))

...is ONE macro invocation.     The next one, if the above form is to be
expanded further as is will (should) fail.

Note that Pete Siebel's Practical Common Lisp has an excellent example of a
ONCE macro (a tool for macros to guarantee argument expressions are
evaluated only once) that relies on the ability to have (unquote <multiple
things> ...)  nested inside a quasiquote form.   This macro is a great test
for your quasiquote implementation (because it does something useful!).

(defmacro once-only ((&rest names) &body body)
  (let ((gensyms (loop for n in names collect (gensym))))
    `(let (,@(loop for g in gensyms collect `(,g (gensym))))
      `(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n)))
        ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g)))
           ,@body)))))
_______________________________________________
Scheme-reports mailing list
[email protected]
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports

Reply via email to