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

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

bug#33828: 26.1; Unbound defvar across compilation units


From: João Távora
Subject: bug#33828: 26.1; Unbound defvar across compilation units
Date: Sat, 22 Dec 2018 02:45:32 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Luís Oliveira <luismbo@gmail.com>
>> Date: Fri, 21 Dec 2018 12:02:55 +0000
>> Cc: João Távora <joaotavora@gmail.com>
>> 
>> I think I've come across a bug.
>
> Doesn't look like a bug to me.

Indeed, it's the behaviour described in the Emacs manual, but the
motivation is questionable: it says it's useful for shooshing the
byte-compiler's warnings.  Aren't there better alternatives to do this
instead of imposing this seeming inconsistency?

>>     (defun f2-foo ()
>>       (let ((my-special 123))
>>         (f2-bar)))
>> 
>>     (defun f2-bar ()
>>       my-special)
>> 
>>     (print (f2-bar))
>> 
>> 
>> 
>>     $ emacs -Q -L . -f batch-byte-compile f2.el
>> 
>>     In toplevel form:
>>     f2.el:5:1:Warning: Unused lexical variable `my-special'
>
> That's because you do nothing with the value of f2-bar.

f2-bar is a function, and it is called.  Did you mean 'my-special'?  It
is used as well, in f2-bar.

>> Also:
>> 
>>     $ emacs -Q -L . -batch -l f2.el
>>     Symbol's value as variable is void: my-special
>
> You need to use defvar in the same file.

Or alternatively, use the variable in a different file but ensure the
defvar was declared with an initial value.  When you do that, it produces
the expected behaviour for someone who is accustomed to other Lisps
lexical and dynamic binding, such as Common Lisp.  In other words, it's
the edge case defvar-in-different-file-with-no-initial-binding that
we're questioning here.  The presence of the initial binding seems to
matter, even though its value is useless.

João







reply via email to

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