From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#66940: Dynamic scoping is all weird now? Date: Mon, 06 Nov 2023 02:52:26 +0100 Message-ID: <87ttpzhcmd.fsf@web.de> References: Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21373"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Gerd =?UTF-8?Q?M=C3=B6llmann?= , 66940@debbugs.gnu.org To: Dave Goel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 06 02:52:51 2023 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 1qzonL-0005OY-Q6 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 06 Nov 2023 02:52:51 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzomz-0001K8-8z; Sun, 05 Nov 2023 20:52:29 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qzomv-0001JQ-Fw for bug-gnu-emacs@gnu.org; Sun, 05 Nov 2023 20:52:25 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzomv-0001rQ-86 for bug-gnu-emacs@gnu.org; Sun, 05 Nov 2023 20:52:25 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qzonW-0005Kq-0L for bug-gnu-emacs@gnu.org; Sun, 05 Nov 2023 20:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 06 Nov 2023 01:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66940 X-GNU-PR-Package: emacs Original-Received: via spool by 66940-submit@debbugs.gnu.org id=B66940.169923558120505 (code B ref 66940); Mon, 06 Nov 2023 01:53:01 +0000 Original-Received: (at 66940) by debbugs.gnu.org; 6 Nov 2023 01:53:01 +0000 Original-Received: from localhost ([127.0.0.1]:38457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzonV-0005Kb-2P for submit@debbugs.gnu.org; Sun, 05 Nov 2023 20:53:01 -0500 Original-Received: from mout.web.de ([212.227.15.3]:53313) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzonT-0005KO-3q for 66940@debbugs.gnu.org; Sun, 05 Nov 2023 20:52:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1699235535; x=1699840335; i=michael_heerdegen@web.de; bh=ZVArgQ73ZvqJQHiGQ/srZAcyDlvjKl0zuVMYXmkRDVc=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References: Date; b=FMt++QQcTxc9jF2QNGoCYZyAUYBO+yyE13ANLJ+Du5NaZ8I62qxzubBhOYElcwkm rfWmrYKiRIvdGOXzC+6QEhfyT1j4TbhM5mv0cZY1BGcIkNvBqyUucNmmD/w9m1OIf TRapnnDaNvaO1nSH81WEKa8X4gqUbO5iEC2TaeY+lMFMF5iY9s5EIooL6VBeVrUcq rOikMjK/v51drlt99RExrje5nJy69/6BJj+iAWbjXq5OQL9dNJAJeZcmEpJ5feUq8 wBMwhhnapNIVjpa+eLD6JZrOQanui+IQGqCdEROu+vxxcA9xZQlD0zdFAOL0m6UpC +klc2bQ9t5grMQmw3A== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([84.59.210.159]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1N4621-1rQawp3ckz-00zlRg; Mon, 06 Nov 2023 02:52:14 +0100 In-Reply-To: (Dave Goel's message of "Sun, 5 Nov 2023 14:07:02 -0500") X-Provags-ID: V03:K1:K/0vqjO6ZUuCM4dZ52QjfUWBz5j5LtvCjiTYLE8//W3FX3ZooK7 W/MRZPFZV4L8g3jLbdLUutgmWAwxE60xI2KfOzpjJqlNYGVRDUD/37zPjCtONf/ApIKJiTJ FTU7J7tx8OULgNK+jkqByO/zolRNLZ7hEEHG8SizaN1+X9rmKldkJxxTlD9yUMYUaEA5hLo VfNLy7n5AetNO/bcm2IoA== UI-OutboundReport: notjunk:1;M01:P0:/uE/vQVgEQ8=;ngNlaRDERZ08hjZtEngLgv0wk/k CbJ362GMgwyoN9U2y+/IkHgtwvtSaIpH8iF7EFn02O7v2kS5ouJ7al2z4NkXO3F9VukOAl9C+ Jy5z3eHIMrXxUxmm1wwSpR0PZ4Hi9KKj6sWguYAk/6u3GlQHwzRQesY7dAeoQhcfJfPyFjBVf TIWp4G06lLWow7aY84ZBDnymkYOsUaYCJA5Q3P388kYUTk93ERQMnnRWeKPa11kPRdGAHuTpc phuFJzUReEFLAvwiI9nmOgeaslqdXPBnP80q5bVlcXZGiFJAMTUiU5FaBkJ0TorprxfhqF4oV B6e3+dGDKVgFNIhaF0WKU+Dt7OF0x4LWlse5swS2arXrT7bFc23irmP2kZd1JtxagNNxJAurT oZeLsTHfHYGDr5uNoFTfe2FtPgq1hNRxYF1Tm933CrcwrobDCMorP9sYnFGEovKi9IaHVfMBo tzEzVcNUAmjED+DTt5ubb+LinuUasE0Ig+KPZff/sBtcmV5pQszzZwriSYYyPIrythdHMy68f Rke6ICOC04AjKOxSHT1iR+mByKpvW4Oqv/dYNM4gD5jQiu082Jctl4PAtHynxR2fV5vOhJ1ag aCNjoFXbrLf+NX29O3ALucI0jZyPEGgXz6TxLCnVTA/Bs4/WHQG4L5GNThazluk2Nue7hd9IN m/HWa5jijXV0TrZLyxlRUraBfw8c/xZFNRKJLUYhiAtdiLQm7ZMcLES9KIMB9/qtIOW/HGN+9 uXM1l8sR8RWcd6+1F9luePsgz3MBYi6rs4XMbBRQS2TVZwSqMWcqBbPC4mQbISYCQtCx5ZVC 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273851 Archived-At: Dave Goel writes: > (progn > (setq lexical-binding nil) > > (dotimes (ii 10) > (defmacro mac () > `(message "%S" ,ii) > ) > (let > ((old_ii ii)) > (setq ii 33) > (mac) > (setq ii old_ii) > ))) This code has two problems: (1) Setting `lexical-binding' in the middle of an evaluation does not work as you think. Either you eval en expression (like the above) using lexical binding or dynamical binding. If you change `lexical-binding' in the middle you might get unexpected behavior. Please set the binding mode only in the file header, not in the code. In the extremely rare cases where you really must evaluate an expression using the other binding mode use `eval' with an appropriate second argument. (2) Macro expansion does not work as you think. Most of the time macros are expanded _once_ in the complete expression and then the result is evaluated. When you redefine a macro in the middle of evaluating code using it, most of the time this will not have an effect because the macro had already been expanded in the following code. > You eval this code once. It works. > You eval this again. It works. > The third time, though, it lands you in the debugger. The very same > code. Why the third time? And, why the debugger? ii is well set every > time it is used. It's not surprising. The first time you start evaluating the expression using lexical binding. Because your code sets lexical-binding to nil, the second time you actually use dynamical binding completely. The third run fails because when `mac' is expanded a variable `ii' is undefined on top-level, so macroexpansion fails. The second run is different: because the first run had used lexical-binding (more or less completely, since you started the interpreter using lexical-binding mode), the macroexpander of `mac' is actually a closure that inherited the value of `ii' from the last iteration of the first run. Because of that the second run succeeds. The second run redefines `mac' so that its reference to `ii' now means the dynamical global variable, which doesn't exist. So, I think everything indeed perfectly works as expected here. Michael.