unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "Mattias Engdegård" <mattiase@acm.org>,
	balducci@units.it, 63586@debbugs.gnu.org
Subject: bug#63586: 29.x: dotimes (possible) problem
Date: Fri, 19 May 2023 13:29:14 -0400	[thread overview]
Message-ID: <jwvlehkcklo.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83ednctipe.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 19 May 2023 19:00:13 +0300")

>> Basically: changing the value of the loop variable in the body of
>> dotimes does not seem to have any effect,

It does, but only within the current iteration, because the variable is
local to the iteration (each iteration gets a fresh new variable).

>> where for versions <29.x it used to.

Indeed it was changed last year for dynamically scoped ELisp to align it
with the semantics used in the lexically scoped ELisp dialect (and thus
simplify the macro).

>> Here is a minimal stretch of dummy code clarifying the problem I'm
>> reporting.
>>
>> emacs-29.0.91 (or 29.0.90)
>> ==========================
>>
>> (dotimes (ii 10)
>> (insert (format "%2d " ii))
>> (when (= ii 4)(setq ii 11))
>> )
>> ==>  0  1  2  3  4  5  6  7  8  9 
>>
>> emacs-28.2 (or any version <29.x)
>> =================================
>>
>> (dotimes (ii 10)
>> (insert (format "%2d " ii))
>> (when (= ii 4)(setq ii 11))
>> )
>> ==>  0  1  2  3  4 
>
> I can only reproduce the behavior you see in 28.2 in Emacs 26.3.  All
> the later versions, starting from 27.1, behave like Emacs 29 does.

AFAIK what the OP describes is new in Emacs-29 (commit
c6c9dfc8670f5698634a8d5853853056ff928974).
But the change only affects code that has not activated
`lexical-binding`: for `lexical-binding`, the behavior has been with us
"forever" (i.e. since Emacs-24, when `lexical-binding` was introduced).

>> AFAICS, changing the value of the loop variable from inside the loop
>> body is supported by any other language which I know about

It's definitely not supported by Common Lisp, which explicitly allows
both our old implementation and our new implementation (i.e. code like
yours may or may not work depending on the CL implementation).
Several other languages (starting with Pascal :-) either disallow or
discourage modifying the iteration variable(s) inside the loop body.

But in any case, the question is not whether it's a good idea or not: it
used to happen to work and now it doesn't work any more.

Maybe we should mention the change in etc/NEWS?


        Stefan






  reply	other threads:[~2023-05-19 17:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 15:10 bug#63586: 29.x: dotimes (possible) problem balducci
2023-05-19 15:54 ` Mattias Engdegård
2023-05-19 16:00 ` Eli Zaretskii
2023-05-19 17:29   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-05-19 17:33     ` Drew Adams
2023-05-19 17:47     ` Eli Zaretskii
2023-05-20  8:56       ` Mattias Engdegård
2023-09-06 20:10         ` bug#63588: " Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvlehkcklo.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=63586@debbugs.gnu.org \
    --cc=balducci@units.it \
    --cc=eliz@gnu.org \
    --cc=mattiase@acm.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).