From: Eli Zaretskii <eliz@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 55156@debbugs.gnu.org
Subject: bug#55156: [PATCH] eval.c: New functions `defvar-f` and `defconst-f`
Date: Thu, 28 Apr 2022 08:34:23 +0300 [thread overview]
Message-ID: <83sfpxbwkg.fsf@gnu.org> (raw)
In-Reply-To: <jwvh76ejj2p.fsf@iro.umontreal.ca> (bug-gnu-emacs@gnu.org)
> Date: Wed, 27 Apr 2022 17:46:22 -0400
> From: Stefan Monnier via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> The bytecode interpreter can't directly call special forms, so
> the byte-compiler usually converts special forms into some sequence of
> byte codes (basically, providing a duplicate definition of the special
> form). There are still two exceptions to this: `defconst` and `defvar`,
> where the compiler instead generates a convoluted chunk of code like:
>
> (funcall '(lambda (x) (defvar <sym> x <doc>)) <value>)
>
> where the quote makes sure we keep the function non-compiled, so as
> to end up running the special form at run time.
>
> The patch below gets rid of this workaround by introducing `defvar-f`
> and `defconst-f` which provide a *functional* interface to the
> functionality of the corresponding special form.
I have (almost) no opinion on the code changes, but the documentation
changes "need work", IMO:
> If @var{value} is specified, and @var{symbol} is void (i.e., it has no
> -dynamically bound value; @pxref{Void Variables}), then @var{value} is
> -evaluated and @var{symbol} is set to the result. But if @var{symbol}
> -is not void, @var{value} is not evaluated, and @var{symbol}'s value is
> -left unchanged. If @var{value} is omitted, the value of @var{symbol}
> +dynamically bound value; @pxref{Void Variables}), then @var{symbol} is
> +set to the result of evaluating of @var{value}. But if @var{symbol}
> +is not void @var{symbol}'s value is left unchanged.
> +If @var{value} is omitted, the value of @var{symbol}
> is not changed in any case.
The new text lacks a comma after "not void", and "result of evaluating
of VALUE" is IMO not good English. If all you wanted was to remove
"is not evaluated", why not just do that and leave the rest as it was?
> -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.
> @@ -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.
> -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?
> +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.
Thanks.
next prev parent reply other threads:[~2022-04-28 5:34 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 [this message]
2022-04-28 13:26 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=83sfpxbwkg.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=55156@debbugs.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).