[emacs-w3m:13908] Re: Fix w3m-puny-encode1 failure on Emacs 29 (PR #116)

Katsumi Yamaoka <[email protected]> Mon, 21 Nov 2022 10:00:11 +0900
Newsgroups gmane.emacs.w3m
Organization Emacsen advocacy group
Message-ID <[email protected]>
In [emacs-w3m:13907]
On Fri, 18 Nov 2022 01:19:36 +0100, Michael Heerdegen wrote:
> I don't understand why dynamical binding is a problem here.

> And explicitly incrementing the counter variable `j` inside the body of
> `dotimes` doesn't look sane: that kind of error doesn't surprise me.
> Do I miss something?

This code intends to stop it immediately by modifying `j':

(dotimes (j 2)
  (setq j 99))

In Emacs 28, that trick does the trick, as the `dotimes' macro
is expanded into the following form if `lexical-binding' is nil
(i.e., the case of w3m-util.el) and byte-compiled into the .elc
file:

(let ((--dotimes-limit-- 2)
      (j 0))
  (while (< j --dotimes-limit--)
    (setq j 99)
    (setq j (1+ j))))

However, even in Emacs 28, it does not work as intended if
`lexical-binding' is t, as it is expanded into:

(let ((--dotimes-limit-- 2)
      (--dotimes-counter-- 0))
  (while (< --dotimes-counter-- --dotimes-limit--)
    (let ((j --dotimes-counter--))
      (setq j 99))
    (setq --dotimes-counter-- (1+ --dotimes-counter--))))

In Emacs 29, the dotimes macro was modified at September so as
to generate the later code only as Kinoshita-san noted:

>  cf.
>  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=c6c9dfc8670f5698634a8d5853853056ff928974