Subject: bug#15538: 24.3; Incorrect Expansion of Nested Backquote

From: 白井 彰 <[email-masked]>
Date: Sun, 6 Oct 2013 20:23:08 +0900

The expansion of nested backquote like

``(,,@q)

or

``(,@,@q)

is incorrect.

Please see the following results.

; The followings are from CLtL2 Appendix C. Backquote

(require 'cl-lib)
cl-lib

(setq q '(r s))
(r s)

(defun r (x) (cl-reduce #'* x))
r

(setq r '(3 5))
(3 5)

(setq s '(4 6))
(4 6)

``(,,q)
(\` ((\, (r s))))
(24)                                    ; Correct

``(,@,q)
(\` ((\,@ (r s))))
24                                      ; Correct

``(,,@q)
(\` ((\, r s)))
((3 5))                                 ; Incorrect: This should be  
((3 5) (4 6))

``(,@,@q)
(\` ((\,@ r s)))
(3 5)                                   ; Incorrect: This should be (3  
5 4 6)

(setq x '(b c))
(b c)

(setq y '(a b))
(a b)

(setq p '(cl-union x y))
(cl-union x y)

(setq q '((cl-union x y) (list 'sqrt 9)))
((cl-union x y) (list (quote sqrt) 9))

(setq r '(cl-union x y))
(cl-union x y)

(setq s '((cl-union x y)))
((cl-union x y))

``(foo ,,p)
(\` (foo (\, (cl-union x y))))
(foo (a b c))                           ; Correct

``(foo ,,@q)
(\` (foo (\, (cl-union x y) (list (quote sqrt) 9))))
(foo (a b c))                           ; Incorrect: This should be  
(foo (a b c) (sqrt 9))

``(foo ,',r)
(\` (foo (\, (quote (cl-union x y)))))
(foo (cl-union x y))                    ; Correct

``(foo ,',@s)
(\` (foo (\, (quote (cl-union x y)))))
(foo (cl-union x y))                    ; Correct

``(foo ,@,p)
(\` (foo (\,@ (cl-union x y))))
(foo a b c)                             ; Correct

``(foo ,@,@q)
(\` (foo (\,@ (cl-union x y) (list (quote sqrt) 9))))
(foo a b c)                             ; Incorrect: This should be  
(foo a b c sqrt 9)

``(foo ,@',r)
(\` (foo (\,@ (quote (cl-union x y)))))
(foo cl-union x y)                      ; Correct

``(foo ,@',@s)
(\` (foo (\,@ (quote (cl-union x y)))))
(foo cl-union x y)                      ; Correct

In GNU Emacs 24.3.1 (i386-apple-darwin9.8.0, NS apple-appkit-949.54)
  of 2013-04-30 on mini2.local
Windowing system distributor `Apple', version 10.3.949
Configured using:
  `configure '--with-ns' '--without-x''

Important settings:
   value of $LANG: ja_JP.ujis
   locale-coding-system: japanese-iso-8bit-unix
   default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
   tooltip-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

Recent input:
<escape> x r e p o r t - e m a c s - b u g <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils time-date japan-util tooltip ediff-hook
vc-hooks lisp-float-type mwheel ns-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process ns multi-tty emacs)