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: Tue, 07 Nov 2023 06:59:44 +0100 Message-ID: <87il6e3xyn.fsf@web.de> References: <87ttpzhcmd.fsf@web.de> 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="32273"; 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 Tue Nov 07 07:01:01 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 1r0F93-0008IY-Iz for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Nov 2023 07:01:01 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0F8e-0004F6-AQ; Tue, 07 Nov 2023 01:00:36 -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 1r0F8U-0004At-M0 for bug-gnu-emacs@gnu.org; Tue, 07 Nov 2023 01:00:30 -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 1r0F8S-0005sU-O7 for bug-gnu-emacs@gnu.org; Tue, 07 Nov 2023 01:00:26 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r0F94-0005yc-2F for bug-gnu-emacs@gnu.org; Tue, 07 Nov 2023 01:01: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: Tue, 07 Nov 2023 06:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66940 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: notabug Original-Received: via spool by 66940-submit@debbugs.gnu.org id=B66940.169933682117347 (code B ref 66940); Tue, 07 Nov 2023 06:01:02 +0000 Original-Received: (at 66940) by debbugs.gnu.org; 7 Nov 2023 06:00:21 +0000 Original-Received: from localhost ([127.0.0.1]:41160 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0F8P-0004UN-06 for submit@debbugs.gnu.org; Tue, 07 Nov 2023 01:00:21 -0500 Original-Received: from mout.web.de ([212.227.15.4]:53599) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0F8M-000425-Cr for 66940@debbugs.gnu.org; Tue, 07 Nov 2023 01:00:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1699336773; x=1699941573; i=michael_heerdegen@web.de; bh=g2+PkVPfmcna6CcJRmZMi/7JQT+ZzgNO2AcvtMnAToM=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References: Date; b=QTW/l3Eb3h0sMt5QqnABCBh5r31DO8/xTs69KDfodq57+9magNu0HaoWtcFavM3h irpWxgx/U8YpT6qtLV/tY3ATUPCbU3Ca7veHeVgaad11a8ooG1xhazRtqzWWn6p2X urWzBI6l1koiUSJvjILpbLptrs920yDT59CZSbF+LbxENXWdU7dWt/IcZXvBTSZ53 +v0U3C0zjBmTAH1IH1WkRFx/KRKAdefIUHlywrl/1zFPW47J/t33xDt5D3mixiOfn NQjjS89X5kG/M92DiFKHOhLoBobLYwUei6l6+D30dHFYh9VHnbhdQFB2ndd0m0g2i +sDotMdHQHZjy/V1UQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([84.59.210.159]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1M59n6-1r1LaD2alY-0018Dd; Tue, 07 Nov 2023 06:59:33 +0100 In-Reply-To: (Dave Goel's message of "Mon, 6 Nov 2023 01:57:05 -0500") X-Provags-ID: V03:K1:NZRbU2v22i3J4JtB1EFkllI0z1OnS5A2iplndT5W/oug2+ZdbHc Z62JS/BksSaZuBOI1M4chSOdU+mIN9qjLjMvBu5BUdbjdlH7pMiAOLtZDVShp/VsCoIgOAb xCubsyIsVrd6CF8YtKxr3LNRhD86VEeValHdAQY3Bh1v0FvLK4qRLJXYZ8dTdEvOxwR06No 5zrAe400/96TfCkuj082w== UI-OutboundReport: notjunk:1;M01:P0:nJsORGzmc84=;Lcngtkd5JQdEhPYImMjE9wh2Rdv YKjvL7YGrFPM0KqAqftKFHUnrOe5BeEl78hZkC0s+YHmlB6s7x6GMRE3p4i52EnwyuHEiQkBb rZgLm6jMwGx7MxI6Wh8eULfWlVrp+8XGMPEwl+vZY/wVAW5lzCxboy0JTLoX1NfYAiFKgafeC /x5o+WiH7a4+7POiodPUhJlDgyPyQ8Dtam7pzmfBBUOI0w9e0q7WZUp94me6qWzzjdIJM+znV Iks2RaBsNZBAyMCTYObK6fC+/MMSyylvSi6aZqe73dARMK7X03oj5q8L1s7CnZZpvtKfRSrG7 w2Hi+QagCIvotcpHfqrwwR5LIveTs4kbOjSLbk1fKW0tXsz0B1LUIEWRtdBHw2udC3aQhe8ZB paBljbTfhSLNII7+lWqTRImuUffL7sFOLoBpR5UGKycdQgMLvp8Buc0zvy3kLBFsIo2jCDyDD pJQutWa7+MJyK80w/c0j13YLyIyHlaq2YIOUgLjwyZT0goVB6t6KTAqUeUp0EqtaPtCNy2gkZ Y7s0Q7fAZ9VSgTANRblKp35HjbkAQHLFQm4pP9HIpwVZ9gh/U/OWt0bcDCze8+t6RRP4qksVw 1Cq3QfKmKfF9lUVNfwmSA87JHXUbEa09S7kthJeFUVXJ0n3Iu0P23mkWbzhc781jHsFv0J+6A F9F/8B3tOi993g5q3nHXHTXf0Te69XluuPM+l9zMCSRf9J1dSTz79MfYwbg3w0sgg45IwysY1 1jWHKC+nf9Mvc8mNpuah7Q8ichOA1qjx5uibACTv+L3evnEvJMneHtyP0UJZeZV7W667RZWy 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:273912 Archived-At: Dave Goel writes: > Let's eval this at the start: > > (setq lexical-binding nil) > > Eval it, so we are operating in the old world of dynamic scoping. Ok, let's do this. > (let ((ii 1)) > (defmacro mac () > `(print ,ii) > ) > (mac)) So now: (symbol-function 'mac) =3D=3D> (macro . (lambda () (list 'print ii))) > [...] > So, let's try this - > > (setq ii 3) > (let ((ii 4)) > (mac)) > > It evals to 3, not 4. Per our understanding of dynamic scoping, we > would have expected it use the innermost ii? Why does it use the > global ii? Remember that macros are not expanded on the fly - they are expanded once for the complete expression in a separate step _before_ the actual evaluation. So: (setq ii 3) ; ii --> 3 Expansion of the second expression: (let ((ii 4)) (mac)) ~~> (let ((ii 4)) (print 3)) ^^^^^^^^^ expansion of (mac) Evaluation: (let ((ii 4)) (print 3)) ; prints "3" A different thing would be to define (defmacro mac () '(print ii)) Then the expansion would still reference the variable. But you could as well just write (print ii) then. To sum up: you are using macros wrong in this case. Macros are not expanded at run-time. It is important to remember that. Note that not even `cl-macrolet' works like this: the definition and scope of the defined macros is local, but they are still expanded before evaluation, so the expansion can't refer to run-time bindings as well. Michael.