From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#55156: [PATCH] eval.c: New functions `defvar-f` and `defconst-f` Date: Thu, 28 Apr 2022 08:34:23 +0300 Message-ID: <83sfpxbwkg.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20193"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 55156@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 28 07:35:19 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1njwoA-00057X-WA for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Apr 2022 07:35:19 +0200 Original-Received: from localhost ([::1]:33452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1njwo9-0004T4-O8 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 28 Apr 2022 01:35:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njwnu-0004QW-38 for bug-gnu-emacs@gnu.org; Thu, 28 Apr 2022 01:35:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51078) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1njwnt-0001Qr-OX for bug-gnu-emacs@gnu.org; Thu, 28 Apr 2022 01:35:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1njwnt-00048s-Iw for bug-gnu-emacs@gnu.org; Thu, 28 Apr 2022 01:35:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Apr 2022 05:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55156 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 55156-submit@debbugs.gnu.org id=B55156.165112407215881 (code B ref 55156); Thu, 28 Apr 2022 05:35:01 +0000 Original-Received: (at 55156) by debbugs.gnu.org; 28 Apr 2022 05:34:32 +0000 Original-Received: from localhost ([127.0.0.1]:44975 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1njwnQ-000483-DW for submit@debbugs.gnu.org; Thu, 28 Apr 2022 01:34:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41044) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1njwnP-00047r-28 for 55156@debbugs.gnu.org; Thu, 28 Apr 2022 01:34:31 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:44428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njwnJ-0001OI-1s; Thu, 28 Apr 2022 01:34:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=horYWMiKXIYErLIVkegQ4OToDOT65Y9okIV107HBfX0=; b=Cj1G8zoyLeKm oeF8IphAMdybDNil1pYWuzPVDkBlWlAUZ6W6d30eic7bgHD64QP/8hDKGkELHRzGZ7JhkNTVBp8wd 0KvBv/daPVv8cNjtQ7evpqMZsrwJE1Mm1cNfDYJMrBe45eStpvxefS/QJ9+2lAblFgyf9DyomKscf DZGfclDmr3L8bkb25o4CY4F/ULGttorvqRH3mKFiVewxKb9bw5NGdQYVPGb462cf+PkMurXKE0CD8 usLQt+fe446O+KZu7RMHT50Kb+CScGqaV9NOF/OmyAxD6pyTu9r1ygo/MRXI86mfHHF1Qsyxx2Gmx J3eFDVwdu731L74sMq+JEw==; Original-Received: from [87.69.77.57] (port=4606 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njwnI-0005UK-GG; Thu, 28 Apr 2022 01:34:24 -0400 In-Reply-To: (bug-gnu-emacs@gnu.org) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:230830 Archived-At: > 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" > > 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 x )) ) > > 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.