all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Double unquote/unquote-splicing
@ 2013-11-04 14:03 Nathan Trapuzzano
  2013-11-04 17:27 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Nathan Trapuzzano @ 2013-11-04 14:03 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-11-05 21:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-04 14:03 Double unquote/unquote-splicing Nathan Trapuzzano
2013-11-04 17:27 ` Stefan Monnier
2013-11-04 17:59   ` Nathan Trapuzzano
2013-11-04 18:11     ` Nathan Trapuzzano
2013-11-04 18:33     ` Stefan Monnier
2013-11-04 19:01       ` Drew Adams
2013-11-04 19:09       ` Nathan Trapuzzano
2013-11-04 20:41         ` Stefan Monnier
2013-11-05 15:03           ` Nathan Trapuzzano
2013-11-05 19:14             ` Stefan Monnier
2013-11-05  4:01         ` Stephen J. Turnbull
2013-11-05 15:22           ` Nathan Trapuzzano
2013-11-05 21:48             ` Stephen J. Turnbull

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.