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

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

Idiomatic way to avoid unused lexical variable in ‘dotimes’ or ‘dolist’?


From: tpeplt
Subject: Idiomatic way to avoid unused lexical variable in ‘dotimes’ or ‘dolist’?
Date: Tue, 26 Mar 2024 18:26:09 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

Consider a file that contains the following lines only:

┌───────────────────────────────
│;; -*- lexical-binding: t; -*-
│
│(dotimes (i 100)
│  (insert "I will not obey absurd orders\n"))
└───────────────────────────────

(Example from the Emacs Lisp manual.)

When this file is byte-compiled, the compiler will issue a warning:

> Warning: Unused lexical variable `i'

The following change could be used to eliminate this warning:

(dotimes (i 100)
  (null i)
  (insert "I will not obey absurd orders\n"))

1. Is there an idiom in Emacs Lisp for writing this that
   eliminates this warning?

2. Should the compiler be changed so that it does not issue this warning
   for ‘dotimes’ and ‘dolist’, where declaring the variable required,
   but use of the variable is optional?

--

reply via email to

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