GNU bug report logs - #11686
24.1.50; defun should return name

Previous Next

Package: emacs;

Reported by: Johan Bockgård <bojohan <at> gnu.org>

Date: Tue, 12 Jun 2012 21:02:02 UTC

Severity: normal

Found in version 24.1.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11686 in the body.
You can then email your comments to 11686 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#11686; Package emacs. (Tue, 12 Jun 2012 21:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Johan Bockgård <bojohan <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 12 Jun 2012 21:02:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Johan Bockgård <bojohan <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.1.50; defun should return name
Date: Tue, 12 Jun 2012 22:58:20 +0200
With current trunk,

   (defun NAME ()) => (lambda nil nil)

   expected        => NAME

Ditto for defmacro.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11686; Package emacs. (Wed, 13 Jun 2012 09:17:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lawrence Mitchell <wence <at> gmx.li>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#11686: 24.1.50; defun should return name
Date: Wed, 13 Jun 2012 10:13:10 +0100
Johan Bockgård wrote:
> With current trunk,

>    (defun NAME ()) => (lambda nil nil)

>    expected        => NAME

> Ditto for defmacro.

Here's a patch, think this is right:

Return NAME, not definition from defun and defmacro

* lisp/emacs-lisp/byte-run.el (defun, defmacro): Return newly created
definition's name, not its definition.


diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 635eef9..fb86b2a 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -135,9 +135,11 @@ interpreted according to `macro-declarations-alist'."
        (if docstring (setq body (cons docstring body)))
        ;; Can't use backquote because it's not defined yet!
        (let* ((fun (list 'function (cons 'lambda (cons arglist body))))
-              (def (list 'defalias
-                         (list 'quote name)
-                         (list 'cons ''macro fun)))
+              (def (cons 'prog1
+                         (list (list 'quote name)
+                               (list 'defalias
+                                     (list 'quote name)
+                                     (list 'cons ''macro fun)))))
               (declarations
                (mapcar
                 #'(lambda (x)
@@ -190,11 +192,13 @@ interpreted according to `defun-declarations-alist'.
                    (t (message "Warning: Unknown defun property %S in %S"
                                (car x) name)))))
                    decls))
-          (def (list 'defalias
-                     (list 'quote name)
-                     (list 'function
-                           (cons 'lambda
-                                 (cons arglist body))))))
+          (def (cons 'prog1
+                     (list (list 'quote name)
+                           (list 'defalias
+                                 (list 'quote name)
+                                 (list 'function
+                                       (cons 'lambda
+                                             (cons arglist body))))))))
       (if declarations
           (cons 'prog1 (cons def declarations))
         def))))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11686; Package emacs. (Wed, 13 Jun 2012 12:31:02 GMT) Full text and rfc822 format available.

Message #11 received at 11686 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lawrence Mitchell <wence <at> gmx.li>
Cc: 11686 <at> debbugs.gnu.org
Subject: Re: bug#11686: 24.1.50; defun should return name
Date: Wed, 13 Jun 2012 08:27:08 -0400
> Here's a patch, think this is right:

> Return NAME, not definition from defun and defmacro

> * lisp/emacs-lisp/byte-run.el (defun, defmacro): Return newly created
> definition's name, not its definition.

I wonder what is the impact on the generated byte-code.

Maybe a simpler way is to change defalias to return the name rather than
the value.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11686; Package emacs. (Wed, 13 Jun 2012 14:38:01 GMT) Full text and rfc822 format available.

Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lawrence Mitchell <wence <at> gmx.li>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#11686: 24.1.50; defun should return name
Date: Wed, 13 Jun 2012 15:34:09 +0100
Stefan Monnier wrote:
>> Here's a patch, think this is right:

>> Return NAME, not definition from defun and defmacro

>> * lisp/emacs-lisp/byte-run.el (defun, defmacro): Return newly created
>> definition's name, not its definition.

> I wonder what is the impact on the generated byte-code.

If the name is thrown away, there's no impact afaict.  If you
assign the name to something there's a small increase.

Here's an example before and after for

(defvar foo (defun foo (&rest x) x))

Before:

(defvar foo (defalias 'foo #[(&rest x) "^H\207" [x] 1]))

After:

(defvar foo (byte-code "\300\301\300\302\"\210\207" [foo defalias #[(&rest x) "^H\207" [x] 1]] 4))

> Maybe a simpler way is to change defalias to return the name rather than
> the value.

But defalias says:

| (defalias SYMBOL DEFINITION &optional DOCSTRING)

| Set SYMBOL's function definition to DEFINITION, and return DEFINITION.

So you'll probably then get a bug report about that instead.

Cheers,

Lawrence
-- 
Lawrence Mitchell <wence <at> gmx.li>





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11686; Package emacs. (Mon, 18 Jun 2012 19:09:01 GMT) Full text and rfc822 format available.

Message #17 received at 11686 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Lawrence Mitchell <wence <at> gmx.li>
Cc: 11686 <at> debbugs.gnu.org
Subject: Re: bug#11686: 24.1.50; defun should return name
Date: Mon, 18 Jun 2012 11:58:09 -0400
>> Maybe a simpler way is to change defalias to return the name rather than
>> the value.
> But defalias says:
> | (defalias SYMBOL DEFINITION &optional DOCSTRING)
> | Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
> So you'll probably then get a bug report about that instead.

We'll see, I just installed a patch that does that.

I don't know of any use-case where the return value of `defalias' is
used, whereas I do know of one use case where the return value of
`defun' is used (it's in (add-hook 'foo-hook (defun bar () ...))).


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11686; Package emacs. (Fri, 22 Jun 2012 13:43:02 GMT) Full text and rfc822 format available.

Message #20 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lawrence Mitchell <wence <at> gmx.li>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#11686: 24.1.50; defun should return name
Date: Fri, 22 Jun 2012 14:38:30 +0100
Stefan Monnier wrote:
>>> Maybe a simpler way is to change defalias to return the name rather than
>>> the value.
>> But defalias says:
>> | (defalias SYMBOL DEFINITION &optional DOCSTRING)
>> | Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
>> So you'll probably then get a bug report about that instead.

> We'll see, I just installed a patch that does that.

I think the following (NEWS) patch should be applied on top.
This is an incompatible change to defalias.  So it should go in
the appropriate part of NEWS.  Additionally, we should mention
defmacro and defun.

diff --git a/etc/NEWS b/etc/NEWS
index 3cd4d21..65f4269 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -418,6 +418,12 @@ Only variables defined using `defcustom' are considered user options.
 The function `user-variable-p' is now an obsolete alias for
 `custom-variable-p'.
 
++++
+** The return values of `defalias', `defun' and `defmacro' have changed,
+and are now undefined.  For backwards compatibility, defun and
+defmacro currently return the name of the newly defined function/macro
+but this should not be relied upon.
+
 ** `face-spec-set' no longer sets frame-specific attributes when the
 third argument is a frame (that usage was obsolete since Emacs 22.2).
 
@@ -434,8 +440,6 @@ still be supported for Emacs 24.x.
 
 * Lisp changes in Emacs 24.2
 
-** The return value of `defalias' has changed and is now undefined.
-
 ** `defun' also accepts a (declare DECLS) form, like `defmacro'.
 The interpretation of the DECLS is determined by `defun-declarations-alist'.
 

-- 
Lawrence Mitchell <wence <at> gmx.li>





Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Sun, 24 Jun 2012 17:12:02 GMT) Full text and rfc822 format available.

Notification sent to Johan Bockgård <bojohan <at> gnu.org>:
bug acknowledged by developer. (Sun, 24 Jun 2012 17:12:02 GMT) Full text and rfc822 format available.

Message #25 received at 11686-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lawrence Mitchell <wence <at> gmx.li>
Cc: 11686-done <at> debbugs.gnu.org
Subject: Re: bug#11686: 24.1.50; defun should return name
Date: Sun, 24 Jun 2012 13:08:02 -0400
> I think the following (NEWS) patch should be applied on top.
> This is an incompatible change to defalias.  So it should go in
> the appropriate part of NEWS.  Additionally, we should mention
> defmacro and defun.

Thanks, installed,


        Stefan




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 23 Jul 2012 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 30 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.