* bug#33199: lambda forms are not self-quoting
@ 2018-10-29 23:06 Noam Postavsky
2018-10-30 7:01 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Noam Postavsky @ 2018-10-29 23:06 UTC (permalink / raw)
To: 33199; +Cc: garreau, alexandre
[-- Attachment #1: Type: text/plain, Size: 369 bytes --]
X-Debbugs-Cc: Garreau, Alexandre <galex-713@galex-713.eu>
Tags: patch
Severity: minor
Alexandre's recent post about pcase-lambda made me notice that lambda's
docstring claims lambda forms are self-quoting. However, they are not:
;; -*- lexical-binding: t -*-
(setq lexical-binding t) ; for *scratch*
(lambda (x) (+ 1 x)) ;=> (closure (t) (x) (+ 1 x))
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2357 bytes --]
From f816c64bf2fe59fc3c77a45d828aea06599f346a Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Mon, 29 Oct 2018 19:01:07 -0400
Subject: [PATCH v1] Don't claim lambda forms are self-quoting
* doc/lispref/functions.texi (Anonymous Functions):
* lisp/subr.el (lambda): Don't say that a lambda form yields itself,
under lexical binding it yields a closure object.
---
doc/lispref/functions.texi | 13 ++-----------
lisp/subr.el | 10 ++++------
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 9b8057080e..09e43621e4 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1082,17 +1082,8 @@ Anonymous Functions
@var{args}, documentation string @var{doc} (if any), interactive spec
@var{interactive} (if any), and body forms given by @var{body}.
-In effect, this macro makes @code{lambda} forms self-quoting:
-evaluating a form whose @sc{car} is @code{lambda} yields the form
-itself:
-
-@example
-(lambda (x) (* x x))
- @result{} (lambda (x) (* x x))
-@end example
-
-The @code{lambda} form has one other effect: it tells the Emacs
-evaluator and byte-compiler that its argument is a function, by using
+The @code{lambda} form has one effect: it tells the Emacs evaluator
+and byte-compiler that its argument is a function, by using
@code{function} as a subroutine (see below).
@end defmac
diff --git a/lisp/subr.el b/lisp/subr.el
index 59f6949b21..1fc58d0ce3 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -93,12 +93,10 @@ def-edebug-spec
`(put (quote ,symbol) 'edebug-form-spec (quote ,spec)))
(defmacro lambda (&rest cdr)
- "Return a lambda expression.
-A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
-self-quoting; the result of evaluating the lambda expression is the
-expression itself. The lambda expression may then be treated as a
-function, i.e., stored as the function value of a symbol, passed to
-`funcall' or `mapcar', etc.
+ "Return an anonymous function.
+A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) evaluates
+to a function, i.e., it may be stored as the function value of a
+symbol, passed to `funcall' or `mapcar', etc.
ARGS should take the same form as an argument list for a `defun'.
DOCSTRING is an optional documentation string.
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#33199: lambda forms are not self-quoting
2018-10-29 23:06 bug#33199: lambda forms are not self-quoting Noam Postavsky
@ 2018-10-30 7:01 ` Eli Zaretskii
2018-10-30 23:07 ` Noam Postavsky
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2018-10-30 7:01 UTC (permalink / raw)
To: Noam Postavsky; +Cc: 33199, garreau, galex-713
> From: Noam Postavsky <npostavs@gmail.com>
> Date: Mon, 29 Oct 2018 19:06:25 -0400
> Cc: garreau@debbugs.gnu.org, alexandre <galex-713@galex-713.eu>
>
> Alexandre's recent post about pcase-lambda made me notice that lambda's
> docstring claims lambda forms are self-quoting. However, they are not:
>
> ;; -*- lexical-binding: t -*-
> (setq lexical-binding t) ; for *scratch*
>
> (lambda (x) (+ 1 x)) ;=> (closure (t) (x) (+ 1 x))
The doc string is still correct if lexical-binding is not in effect,
isn't it?
> From: Noam Postavsky <npostavs@gmail.com>
> Date: Mon, 29 Oct 2018 19:01:07 -0400
> Subject: [PATCH v1] Don't claim lambda forms are self-quoting
>
> * doc/lispref/functions.texi (Anonymous Functions):
> * lisp/subr.el (lambda): Don't say that a lambda form yields itself,
> under lexical binding it yields a closure object.
This removes useful information, IMO. I'd be much happier if we added
to the existing docs that lambda is not self-quoting in the
lexical-binding environment, and described (and explained) what does
happen in the lexical-binding environment.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#33199: lambda forms are not self-quoting
2018-10-30 7:01 ` Eli Zaretskii
@ 2018-10-30 23:07 ` Noam Postavsky
2018-10-31 16:06 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Noam Postavsky @ 2018-10-30 23:07 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 33199, garreau, galex-713
[-- Attachment #1: Type: text/plain, Size: 469 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
> This removes useful information, IMO.
What's it really useful for though? IMO, all anyone needs to know is
that (lambda ...) evaluates to a function.
> I'd be much happier if we added to the existing docs that lambda is
> not self-quoting in the lexical-binding environment, and described
> (and explained) what does happen in the lexical-binding environment.
It seems to me like too much useless detail, but if you insist.
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2655 bytes --]
From bd397a3cec219a453e3118cb59e5955f5a09b870 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Mon, 29 Oct 2018 19:01:07 -0400
Subject: [PATCH v2] Note that lambda forms are not self-quoting under lex
binding
* doc/lispref/functions.texi (Anonymous Functions):
* lisp/subr.el (lambda): Note that under lexical binding it yields a
closure object (Bug#33199).
---
doc/lispref/functions.texi | 9 ++++++---
lisp/subr.el | 13 +++++++------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 9b8057080e..7f8a6fc40b 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1082,15 +1082,18 @@ Anonymous Functions
@var{args}, documentation string @var{doc} (if any), interactive spec
@var{interactive} (if any), and body forms given by @var{body}.
-In effect, this macro makes @code{lambda} forms self-quoting:
-evaluating a form whose @sc{car} is @code{lambda} yields the form
-itself:
+Under dynamic binding, this macro effectively makes @code{lambda}
+forms self-quoting: evaluating a form whose @sc{car} is @code{lambda}
+yields the form itself:
@example
(lambda (x) (* x x))
@result{} (lambda (x) (* x x))
@end example
+Note that when evaluting under lexical binding the result is a closure
+object (@pxref{Closures}).
+
The @code{lambda} form has one other effect: it tells the Emacs
evaluator and byte-compiler that its argument is a function, by using
@code{function} as a subroutine (see below).
diff --git a/lisp/subr.el b/lisp/subr.el
index 59f6949b21..d09789340f 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -93,12 +93,13 @@ def-edebug-spec
`(put (quote ,symbol) 'edebug-form-spec (quote ,spec)))
(defmacro lambda (&rest cdr)
- "Return a lambda expression.
-A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
-self-quoting; the result of evaluating the lambda expression is the
-expression itself. The lambda expression may then be treated as a
-function, i.e., stored as the function value of a symbol, passed to
-`funcall' or `mapcar', etc.
+ "Return an anonymous function.
+Under dynamic binding, a call of the form (lambda ARGS DOCSTRING
+INTERACTIVE BODY) is self-quoting; the result of evaluating the
+lambda expression is the expression itself. Under lexical
+binding, the result is a closure. Regardless, the result is a
+function, i.e., it may be stored as the function value of a
+symbol, passed to `funcall' or `mapcar', etc.
ARGS should take the same form as an argument list for a `defun'.
DOCSTRING is an optional documentation string.
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#33199: lambda forms are not self-quoting
2018-10-30 23:07 ` Noam Postavsky
@ 2018-10-31 16:06 ` Eli Zaretskii
2018-11-09 1:26 ` Noam Postavsky
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2018-10-31 16:06 UTC (permalink / raw)
To: Noam Postavsky; +Cc: 33199, garreau, galex-713
> From: Noam Postavsky <npostavs@gmail.com>
> Cc: 33199@debbugs.gnu.org, garreau@debbugs.gnu.org, galex-713@galex-713.eu
> Date: Tue, 30 Oct 2018 19:07:16 -0400
>
> > This removes useful information, IMO.
>
> What's it really useful for though? IMO, all anyone needs to know is
> that (lambda ...) evaluates to a function.
It sounds non-trivial to me, and someone obviously thought it was
important enough to write that text.
> > I'd be much happier if we added to the existing docs that lambda is
> > not self-quoting in the lexical-binding environment, and described
> > (and explained) what does happen in the lexical-binding environment.
>
> It seems to me like too much useless detail, but if you insist.
Thanks the updated patch LGTM.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#33199: lambda forms are not self-quoting
2018-10-31 16:06 ` Eli Zaretskii
@ 2018-11-09 1:26 ` Noam Postavsky
0 siblings, 0 replies; 5+ messages in thread
From: Noam Postavsky @ 2018-11-09 1:26 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 33199, galex-713
tags 33199 fixed
close 33199 26.2
quit
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Noam Postavsky <npostavs@gmail.com>
>> Cc: 33199@debbugs.gnu.org, garreau@debbugs.gnu.org, galex-713@galex-713.eu
>> Date: Tue, 30 Oct 2018 19:07:16 -0400
>>
>> > This removes useful information, IMO.
>>
>> What's it really useful for though? IMO, all anyone needs to know is
>> that (lambda ...) evaluates to a function.
>
> It sounds non-trivial to me, and someone obviously thought it was
> important enough to write that text.
Hmm, it's hard to argue with the anonymous absentee.
> Thanks the updated patch LGTM.
Okay, pushed to emacs-26.
[1: 39e85a0c6c]: 2018-11-08 20:13:56 -0500
Note that lex bound lambda forms are not self-quoting (Bug#33199)
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=39e85a0c6c8de75b446e8e4dc41cdfdca96907e3
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-11-09 1:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-29 23:06 bug#33199: lambda forms are not self-quoting Noam Postavsky
2018-10-30 7:01 ` Eli Zaretskii
2018-10-30 23:07 ` Noam Postavsky
2018-10-31 16:06 ` Eli Zaretskii
2018-11-09 1:26 ` Noam Postavsky
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).