From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 55156@debbugs.gnu.org
Subject: bug#55156: [PATCH] eval.c: New functions `defvar-f` and `defconst-f`
Date: Thu, 28 Apr 2022 09:26:50 -0400 [thread overview]
Message-ID: <jwvr15hic1a.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83sfpxbwkg.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 28 Apr 2022 08:34:23 +0300")
>> -If @var{symbol} is already lexically bound (e.g., if the @code{defvar}
>> -form occurs in a @code{let} form with lexical binding enabled), then
>> -@code{defvar} sets the dynamic value. The lexical binding remains in
>> +If @var{symbol} is already let bound (e.g., if the @code{defvar}
>> +form occurs in a @code{let} form), then @code{defvar} sets the dynamic
>> +outer value. The let binding remains in
>
> What is "dynamic outer value"? We don't have such terminology
> anywhere in the manual.
Good point, I should try and use the same terminology used by
`default-toplevel-value` (and maybe refer to this function), thanks.
>> @@ -763,17 +763,14 @@ DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
>> so that it is always dynamically bound even if `lexical-binding' is t.
>>
>> If SYMBOL's value is void and the optional argument INITVALUE is
>> -provided, INITVALUE is evaluated and the result used to set SYMBOL's
>> -value. If SYMBOL is buffer-local, its default value is what is set;
>> +provided, INITVALUE is used to set SYMBOL's value.
>> +If SYMBOL is buffer-local, its default value is what is set;
>> buffer-local values are not affected. If INITVALUE is missing,
>> SYMBOL's value is not set.
>
> This loses information, AFAIU: the previous doc string said INITVALUE
> was evaluated, the new one says nothing at all about evaluating it.
> If it is evaluated in some cases, please mention that; if it isn't
> evaluated at all, please say that.
I hesitated here. I preferred to remove the promise of when it's
evaluated (which we currently break in some cases) rather than make
a different promise, incompatible with the previous one.
But now that Lars made me see that we actually do hold the promise in
most cases, I think the better course of action is to keep the promise
and fix the cases where we break it.
>> -If SYMBOL has a local binding, then this form affects the local
>> -binding. This is usually not what you want. Thus, if you need to
>> -load a file defining variables, with this form or with `defconst' or
>> -`defcustom', you should always load that file _outside_ any bindings
>> -for these variables. (`defconst' and `defcustom' behave similarly in
>> -this respect.)
>> +If SYMBOL is let-bound, then this form does not affect the local let
>> +binding but the outer (toplevel) binding.
>> +(`defcustom' behaves similarly in this respect.)
>
> Isn't _this_ change (if it indeed constitutes a change in behavior)
> scary?
It was scary, yes, but that change happened back in:
commit a104f656c8217b027866d32e8d7bf024a671e3cc
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Fri Aug 2 17:16:33 2013 -0400
Make defvar affect the default binding outside of any let.
* src/eval.c (default_toplevel_binding): New function.
(Fdefvar): Use it.
(unbind_to, backtrace_eval_unrewind): Do a bit of CSE simplification.
(Fdefault_toplevel_value, Fset_default_toplevel_value): New subrs.
(syms_of_eval): Export them.
* src/data.c (Fdefault_value): Micro cleanup.
* src/term.c (init_tty): Use "false".
* lisp/custom.el (custom-initialize-default, custom-initialize-set)
(custom-initialize-reset, custom-initialize-changed): Affect the
toplevel-default-value (bug#6275, bug#14586).
* lisp/emacs-lisp/advice.el (ad-compile-function): Undo previous workaround
for bug#6275.
* test/automated/core-elisp-tests.el: New file.
So this is just a long-overdue fix of its doc.
>> +DEFUN ("defvar-f", Fdefvar_f, Sdefvar_f, 2, 3, 0,
>> + doc: /* Like `defvar' but as a function. */)
>
> Please improve the doc string here.
>
>> +DEFUN ("defconst-f", Fdefconst_f, Sdefconst_f, 2, 3, 0,
>> + doc: /* Like `defconst' but as a function. */)
>
> Likewise.
How 'bout I use a double dash to make it more clear they're internal?
Stefan
next prev parent reply other threads:[~2022-04-28 13:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-27 21:46 bug#55156: [PATCH] eval.c: New functions `defvar-f` and `defconst-f` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-27 22:11 ` Lars Ingebrigtsen
2022-04-27 22:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-27 22:33 ` Lars Ingebrigtsen
2022-04-28 1:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-28 5:44 ` Eli Zaretskii
2022-04-29 3:10 ` Richard Stallman
2022-04-28 5:34 ` Eli Zaretskii
2022-04-28 13:26 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-04-28 13:30 ` Lars Ingebrigtsen
2022-04-28 13:33 ` Lars Ingebrigtsen
2022-04-28 13:45 ` Eli Zaretskii
2022-04-29 3:10 ` Richard Stallman
2022-05-25 20:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-26 5:01 ` Eli Zaretskii
2022-05-27 1:27 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-29 3:10 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvr15hic1a.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=55156@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).