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: Stefan Monnier
Subject: Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?
Date: Thu, 07 Jan 2021 22:39:13 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> (defun pct-plus-times (amount percent times)
>   "Return AMOUNT increased for PERCENT for number of TIMES."
>   (dotimes (var times amount)
>     (setq amount (pct-plus amount percent))))
>
> And I see that `var' is unused there. I have never used those
> functions in a package so there were no warnings.

You can eliminate the warning as follows:

    (defun pct-plus-times (amount percent times)
      "Return AMOUNT increased for PERCENT for number of TIMES."
      (dotimes (var times)
        (setq amount (pct-plus amount percent)))
      amount)

No need to resort to `while`.


        Stefan




reply via email to

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