From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dave Goel Newsgroups: gmane.emacs.devel Subject: An MRE or other hints for this macro / dynamic scoping bug? Date: Sun, 5 Nov 2023 14:57:42 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000028d74306096d273a" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7202"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org, Dave Goel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 05 20:58:56 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qzjGp-0001k1-RB for ged-emacs-devel@m.gmane-mx.org; Sun, 05 Nov 2023 20:58:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzjFv-00064v-BA; Sun, 05 Nov 2023 14:57:59 -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 1qzjFs-00064m-NZ for emacs-devel@gnu.org; Sun, 05 Nov 2023 14:57:56 -0500 Original-Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzjFr-0007ey-6L for emacs-devel@gnu.org; Sun, 05 Nov 2023 14:57:56 -0500 Original-Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-7a689bd4928so114013439f.0 for ; Sun, 05 Nov 2023 11:57:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699214273; x=1699819073; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=mN3Do9Ak3g3WwgFr1gBk65ro9nU81uPFHj9hndWiKgw=; b=dPWHJcjarxkXjsSs74b1J4lq4V1HP+gJ1rlYpGTpFpH2XN5F4sxDdxjnluGSAkLoea pXViLqzdoDRF3IJ56K71iBC5xis5XYChBFGZaznd1Q3JTHbVX9ZCr7Z6iWE29r3Mv79v qt3wZm0Oe4JEyX0jdkJkvnLDJQLqxl2QRNL5w7v5B0CSErClkuuz+kEzE0p31VJI0sLF BoupLMpSCafBGfZWNYfUo/1NFggAQxoPrgMViPuIetSuunT6117Gyn2ridS/ulwiXLl+ Yh8cuEkZg3X4OdE5J6Vpmc2DjMFFB1JjjhZLXYBDrC22Z2PYm3RlWfoGYbk/yN1wnfnB i+Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699214273; x=1699819073; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mN3Do9Ak3g3WwgFr1gBk65ro9nU81uPFHj9hndWiKgw=; b=pCC5JzTaEl4Ti22NsWYMGQ8K3NUy42I/o1dlddXoKvp0JZGKNFH6fCciG5Wc2wVE1P tZjBJTYNeXb6dqnJeYAqq6emeMAr1uWZSA7XbSau+OZd1Q1hzKG70qnkuMKnkvtQptAA ZvAvTzyCJjyx7+E2oWisfI+QBMUy2+Wb0wpvs3zxTzsbrM+5oFNRS4g9rPetWeCUg1/b WV4xxITdE86SrwbyK8INEmMD9Gcxm9D2p1PrHhrZinZNU1wNwDQz1vL9Miw3RjlAwvQH 4ypYuOj6GkUvBRGy0HVl3BWB/LRRbwEPUkeJpG20oRt52Q2+P/GnS1pn+EJOnQGHNx7W sRSQ== X-Gm-Message-State: AOJu0YxlTXtAHU1zEzlWO9IjXag4KX4Ji+MlS7IQSi6Y5vME4tMtk9Uq fTyj1X6VM/8UHikWNpwkukHiaOvx9zI9li+KmF5ydfUA0os= X-Google-Smtp-Source: AGHT+IGH0htQ5zkvfOClGQ7FLj6ybJRV4iE+BBlKe07Uru79mQ9I8tKxZu9rXw9knHbC1LFXY9vbqsw+emN6K1kQ7Is= X-Received: by 2002:a92:c541:0:b0:359:430f:4fdc with SMTP id a1-20020a92c541000000b00359430f4fdcmr7308394ilj.13.1699214273335; Sun, 05 Nov 2023 11:57:53 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::d2f; envelope-from=deego3@gmail.com; helo=mail-io1-xd2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:312256 Archived-At: --00000000000028d74306096d273a Content-Type: text/plain; charset="UTF-8" Hey Emacsers, I'm likely losing my mind. Is this not a bug, below? I tried discussing on #emacs first, and then reported (a slightly more complex version). But, it's perhaps not obvious, and it was suggested I try to produce a simpler example. I realize I should have discussed it here first, before reporting it. A discussion here would probably produce a much better bug report in any case. Do you guys see an obvious bug here? Any simpler versions you can think of? Any hints where the bug could lie? Basically, I define a macro that hardcodes the value of our variable ii that existed before the macro definition. And, then try to use it. (progn (setq lexical-binding nil) (dotimes (ii 10) (defmacro mac () `(message "%S" ,ii) ) (mac))) That's the code. Eval it once. Works. Eval it again. Works. Eval it the third time. Debugger entered. Tested in emacs -Q in 28 and 29. [[a]] In fact, before you eval it the third time, if you change ii to jj, it still complains about ii. [[b]] Bugs are the behaviors (a) and (b) above. The macro expands to (list 'message "%S" ii). That should have worked, right? Because ii was already set at the time of definition? Here's the debugger behavior - Debugger entered--Lisp error: (void-variable ii) (list 'message "%S" ii) --00000000000028d74306096d273a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hey Emacsers,

I'm likely losing m= y mind. Is this not a bug, below?

I tried discussing on #emacs firs= t, and then reported (a slightly more complex version). But, it's perha= ps not obvious, and it =C2=A0was suggested I try to produce a simpler examp= le.

I realize I should have discussed it here first, before reportin= g it.=C2=A0 A discussion here would probably produce a much better bug repo= rt in any case.

Do you guys see an obvious bug here? Any simpler ve= rsions you can think of?=C2=A0 Any hints where the bug could lie?

B= asically, I define a macro that hardcodes the value of our variable ii that= existed before the macro definition.

And, then try to use it.

(progn
=C2=A0 (setq lexical-binding nil)

=C2=A0 (dotimes (i= i 10)
=C2=A0 =C2=A0 (defmacro mac ()
=C2=A0 =C2=A0 =C2=A0 `(message &= quot;%S" ,ii)
=C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0 (mac)))

That's the code.
Eval it once. Works.
Eval it again. Works.=

Eval it the third time. Debugger entered. Tested in emacs -Q in 28 = and 29. [[a]]

In fact, before you eval it the third time, if you cha= nge ii to jj, it still complains about ii. [[b]]

Bugs are the behavi= ors =C2=A0(a) and (b) above.

The= macro expands to (list 'message "%S" ii). That should have w= orked, right? Because ii was already set at the time of definition?=C2=A0

Here's the debugger behavior = -=C2=A0
Debugger entered--Lisp error: (void-variable ii)=
=C2=A0 (list 'message "%S" ii)
--00000000000028d74306096d273a--