[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Idiomatic way to avoid unused lexical variable in ‘dotimes’ or ‘doli
From: |
Tim Landscheidt |
Subject: |
Re: Idiomatic way to avoid unused lexical variable in ‘dotimes’ or ‘dolist’? |
Date: |
Wed, 27 Mar 2024 03:52:47 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) |
(anonymous) wrote:
>>> 1. Is there an idiom in Emacs Lisp for writing this that
>>> eliminates this warning?
>> (dotimes (_ 100)
>> (insert "I will not obey absurd orders\n"))
>> Or any other var name that starts with an underscore.
> Thank you. I have not been able to find this documented anywhere (that
> is, that lexical variables whose names begin with an underscore are not
> flagged with a warning message if they are not referenced). This
> appears to be true with, for example, ‘let’ expressions, also.
It is mentioned in the GNU Emacs Lisp Reference Manual (C-h
i g (elisp) RET) in the node "Converting to Lexical
Binding":
| […]
| A warning about an unused variable may be a good hint that the
| variable was intended to be dynamically scoped (because it is actually
| used, but in another function), but it may also be an indication that
| the variable is simply really not used and could simply be removed. So
| you need to find out which case it is, and based on that, either add a
| ‘defvar’ or remove the variable altogether. If removal is not possible
| or not desirable (typically because it is a formal argument and that we
| cannot or don’t want to change all the callers), you can also add a
| leading underscore to the variable’s name to indicate to the compiler
| that this is a variable known not to be used.)
| […]
Tim