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

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

Re: How to avoid compiler warning `unused lexical variable' for `dolist'


From: Tomas Hlavaty
Subject: Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?
Date: Sun, 10 Jan 2021 10:20:45 +0100

On Sat 09 Jan 2021 at 14:01, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>>       (let ((i --dotimes-counter--)) plist))
>>
>> In Common Lisp, that part would be solved by (declare (ignorable i)) in
>> the macro:
>>
>> (let ((i --dotimes-counter--))
>>   (declare (ignorable i))
>>   plist)
>>
>> I do not know if Emacs Lisp has ignorable.
>
> We have something equivalent:
>
>     (let ((i --dotimes-counter--))
>       (ignore i)
>       plist)
>
> [ Which "comes for free" in the sense that it is not the result of
>   deliberate design but rather the simple fact that the `ignore`
>   function is usually optimized away (but it's optimized late enough
>   that the `i` passed to it still counts as a use of that variable).  ]

I see that Emacs Lisp does not have a way to distinguish the two cases.

In Common Lisp, (declare (ignore i)) means ignore unused variable i.  If
i is used, I get a warning.  (declare (ignorable i)) means ignore the
variable in case it is unused, which is useful in cases like the one
discussed here where the author of the macro does not know upfront, if
the variable i should or should not be ignored.

If the dotimes macro contained (ignore i) but the user returned i, I
would expect warning:

(let ((i --dotimes-counter--))
  (ignore i)
  i)

It is a shame that Emacs Lisp does not do that.



reply via email to

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