* bug#11686: 24.1.50; defun should return name
@ 2012-06-12 20:58 Johan Bockgård
2012-06-13 9:13 ` Lawrence Mitchell
0 siblings, 1 reply; 7+ messages in thread
From: Johan Bockgård @ 2012-06-12 20:58 UTC (permalink / raw)
To: 11686
With current trunk,
(defun NAME ()) => (lambda nil nil)
expected => NAME
Ditto for defmacro.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#11686: 24.1.50; defun should return name
2012-06-12 20:58 bug#11686: 24.1.50; defun should return name Johan Bockgård
@ 2012-06-13 9:13 ` Lawrence Mitchell
2012-06-13 12:27 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Lawrence Mitchell @ 2012-06-13 9:13 UTC (permalink / raw)
To: 11686
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))))
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#11686: 24.1.50; defun should return name
2012-06-13 9:13 ` Lawrence Mitchell
@ 2012-06-13 12:27 ` Stefan Monnier
2012-06-13 14:34 ` Lawrence Mitchell
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2012-06-13 12:27 UTC (permalink / raw)
To: Lawrence Mitchell; +Cc: 11686
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#11686: 24.1.50; defun should return name
2012-06-13 12:27 ` Stefan Monnier
@ 2012-06-13 14:34 ` Lawrence Mitchell
2012-06-18 15:58 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Lawrence Mitchell @ 2012-06-13 14:34 UTC (permalink / raw)
To: 11686
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@gmx.li>
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#11686: 24.1.50; defun should return name
2012-06-13 14:34 ` Lawrence Mitchell
@ 2012-06-18 15:58 ` Stefan Monnier
2012-06-22 13:38 ` Lawrence Mitchell
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2012-06-18 15:58 UTC (permalink / raw)
To: Lawrence Mitchell; +Cc: 11686
>> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#11686: 24.1.50; defun should return name
2012-06-18 15:58 ` Stefan Monnier
@ 2012-06-22 13:38 ` Lawrence Mitchell
2012-06-24 17:08 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Lawrence Mitchell @ 2012-06-22 13:38 UTC (permalink / raw)
To: 11686
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.
\f
* 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@gmx.li>
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-06-24 17:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-12 20:58 bug#11686: 24.1.50; defun should return name Johan Bockgård
2012-06-13 9:13 ` Lawrence Mitchell
2012-06-13 12:27 ` Stefan Monnier
2012-06-13 14:34 ` Lawrence Mitchell
2012-06-18 15:58 ` Stefan Monnier
2012-06-22 13:38 ` Lawrence Mitchell
2012-06-24 17:08 ` 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).