[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Double unquote/unquote-splicing
From: |
Nathan Trapuzzano |
Subject: |
Double unquote/unquote-splicing |
Date: |
Mon, 04 Nov 2013 09:03:11 -0500 |
User-agent: |
Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3.50 (gnu/linux) |
This was a subject of discussion not too long ago. Someone wrote to say
how unquote and unquote-splicing don't pile up properly (as in ,,@FORM
or ,@,@FORM). In fact, they do work properly in the case that the inner
unquote-splicing expands to just one form, but this is hardly a useful
case (it's easily re-writable in other terms). On the other hand, there
are useful cases of ,,@ and ,@,@ that cannot be written without
rendering the code virtually unreadable. Consider:
(defmacro once-only (names &rest 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)))))
(defmacro once-only (names &rest body)
(let ((gensyms (loop for n in names collect (gensym))))
`(let (,@(loop for g in gensyms collect `(,g (gensym))))
(append (list `let)
(list (append
(list ,@(loop for g in gensyms for n in names
collect `(append (list ,g) (list ,n))))))
(list
(let (,@(loop for n in names for g in gensyms
collect `(,n ,g)))
,@body))))))
These two macros are semantically equivalent, but one is infinitely more
easy to read thanks to ,,@. However, only the latter form works in
Emacs when NAMES has length > 1.
For the sake of readability, I'd like to propose properly implementing
,,@ and ,@,@ etc. Is this doable without major changes to the current
backquote implementation? If so, is there some other reason why this
should _not_ be done?
Nathan
- Double unquote/unquote-splicing,
Nathan Trapuzzano <=
- Re: Double unquote/unquote-splicing, Stefan Monnier, 2013/11/04
- Re: Double unquote/unquote-splicing, Nathan Trapuzzano, 2013/11/04
- Re: Double unquote/unquote-splicing, Nathan Trapuzzano, 2013/11/04
- Re: Double unquote/unquote-splicing, Stefan Monnier, 2013/11/04
- RE: Double unquote/unquote-splicing, Drew Adams, 2013/11/04
- Re: Double unquote/unquote-splicing, Nathan Trapuzzano, 2013/11/04
- Re: Double unquote/unquote-splicing, Stefan Monnier, 2013/11/04
- Re: Double unquote/unquote-splicing, Nathan Trapuzzano, 2013/11/05
- Re: Double unquote/unquote-splicing, Stefan Monnier, 2013/11/05
- Re: Double unquote/unquote-splicing, Stephen J. Turnbull, 2013/11/04