bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59057: Emacs 29. Byte compiler sometimes forgets about a defvar.


From: Stefan Monnier
Subject: bug#59057: Emacs 29. Byte compiler sometimes forgets about a defvar.
Date: Mon, 07 Nov 2022 16:29:15 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

>> (defvar VAR) does not "create a variable".
>
> According to both its doc string and the Elisp manual it does.

Where?  I'm talking specifically about (defvar VAR) not about
`defvar` in general.

>> It just "locally" declares that this identifier should use dynamic
>> scoping when binding a variable.
> Why "locally"?  There's just one obarray involved, which is global.

No, we want to allow `defvar` to have a lexically-local effect.

>> But the better way to write the above code is:
>
>>     (defmacro acm-defvar (var)
>>       `(progn
>>          (defvar ,var)
>>          (eval-when-compile
>>            (when (version-check)
>>              (setq ,var emacs-major-version)))))
>
> There are workarounds, yes.  But surely it would be better to fix the
> bug.

It's not a workaround.  It's how the programmers say whether they want
the (defvar ,var) declaration to affect all the rest of the code or only
the code within the `when`.

Why put the (defvar ,var) within the `when` if not to limit
its scope?


        Stefan






reply via email to

[Prev in Thread] Current Thread [Next in Thread]