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: Sat, 09 Jan 2021 18:14:49 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> This distinction becomes relevant if BODY modifies VAR or captures it
>> in a closure.
> Maybe I am being thick, but I cannot think of how there would be a
> different behaviour.

Try:

    (let (funs)
      (dotimes (i 5)
        (push (lambda () i) funs))
      (mapcar #'funcall funs))

IIUC the version you advocate would return

    (5 5 5 5 5)

whereas the current version returns

    (4 3 2 1 0)

Other differences occur if you do

    (let (vals)
      (dotimes (i 10)
        (push (setq i (1+ i)) vals))
      vals)


-- Stefan




reply via email to

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