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: Leo Butler
Subject: Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?
Date: Sat, 09 Jan 2021 17:06:23 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Philipp Stephani <p.stephani2@gmail.com> writes:

> Am Sa., 9. Jan. 2021 um 14:30 Uhr schrieb Leo Butler 
> <leo.butler@umanitoba.ca>:
>>
>> Stefan,
>>
>> I wonder why the lexical-binding version of dotimes is not implemented
>> like:
>>
>> #+begin_src emacs-lisp
>>   (let* ((start 0) (end (nth 1 spec)) (counter (gensym))
>>          (body (subst counter (car spec) body)))
>>           `(let ((,counter ,start))
>>              (while (< ,counter ,end)
>>                ,@body
>>                (setq ,counter (1+ ,counter)))
>>              ,@ (cddr spec))))
>> #+end_src
>
> That would be a semantically different operation. `dotimes' guarantees
> that the counter variable is let-bound within each iteration. That
> means that the macro expansion needs to contain something like
> (let ((VAR ...)) BODY)
> 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.

Note that I am discussing only the lexical scope case. The macro
replaces each occurrence of VAR (=(car spec)) in BODY with the gensym.

>
>> I am familiar with the comment in subr.el about uninterned symbols, but
>> TBH, I don't have a sense of where the performance penalty might be
>> of any significant size.
>
> The uninterned vs. interned distinction is unrelated. `dotimes'
> chooses to use an interned symbol as a micro-optimization, but it
> doesn't affect its behavior.

The current dotimes macro is unhygenic, isn't it, whereas using an
uninterned symbol would make it hygenic. So, yes, I think there is a
difference in behavior.

Leo



reply via email to

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