unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Understanding macroexp.el
@ 2015-11-18 10:32 Michael Heerdegen
  2015-11-18 11:37 ` Andreas Schwab
  2015-11-18 13:40 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Heerdegen @ 2015-11-18 10:32 UTC (permalink / raw)
  To: Emacs Development; +Cc: Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

Hello,

yesterday I tried to understand the helpers in macroexp.el.  I have a
question:

Would it make sense to install the following:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: macroexp.patch --]
[-- Type: text/x-diff, Size: 740 bytes --]

*** /tmp/ediff139941AX	2015-11-18 11:12:07.788012282 +0100
--- /home/micha/software/emacs/lisp/emacs-lisp/macroexp.el	2015-11-18 10:47:41.041352909 +0100
***************
*** 331,337 ****
    (cond
     ((null bindings) exp)
     ((eq 'let* (car-safe exp)) `(let* (,@bindings ,@(cadr exp)) ,@(cddr exp)))
!    (t `(let* ,bindings ,exp))))
  
  (defun macroexp-if (test then else)
    "Return an expression equivalent to `(if ,TEST ,THEN ,ELSE)."
--- 331,337 ----
    (cond
     ((null bindings) exp)
     ((eq 'let* (car-safe exp)) `(let* (,@bindings ,@(cadr exp)) ,@(cddr exp)))
!    (t `(let* ,bindings ,@(macroexp-unprogn exp)))))
  
  (defun macroexp-if (test then else)
    "Return an expression equivalent to `(if ,TEST ,THEN ,ELSE)."

[-- Attachment #3: Type: text/plain, Size: 479 bytes --]


Here is an example where it matters:

(defmacro test (exp)
  (macroexp-let2 nil res exp
    `(progn
       (f ,res)
       (g ,res))))

(note that the `progn' is mandatory here.)  Without the patch:

(macroexpand '(test (+ 1 2)))
==>
(let*
    ((#:res #1=(+ 1 2)))
  (progn
    (f #1#)
    (g #1#)))


After patch:

(macroexpand '(test (+ 1 2)))
==>
(let*
    ((#:res #1=(+ 1 2)))
  (f #1#)
  (g #1#))


(And is it currently allowed to push this to master?)


Thanks,

Michael.

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

end of thread, other threads:[~2015-11-18 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-18 10:32 Understanding macroexp.el Michael Heerdegen
2015-11-18 11:37 ` Andreas Schwab
2015-11-18 12:03   ` Michael Heerdegen
2015-11-18 13:36     ` Stefan Monnier
2015-11-18 13:40 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).