GNU bug report logs - #63586
29.x: dotimes (possible) problem

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: balducci@HIDDEN; merged with #63588; dated Fri, 19 May 2023 15:12:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Merged 63586 63588. Request was from Eli Zaretskii <eliz@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 63586 <at> debbugs.gnu.org:


Received: (at 63586) by debbugs.gnu.org; 19 May 2023 16:00:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 19 12:00:08 2023
Received: from localhost ([127.0.0.1]:57214 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1q02WW-00023o-AQ
	for submit <at> debbugs.gnu.org; Fri, 19 May 2023 12:00:08 -0400
Received: from eggs.gnu.org ([209.51.188.92]:51786)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1q02WU-00021d-2T
 for 63586 <at> debbugs.gnu.org; Fri, 19 May 2023 12:00:06 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1q02WN-0003XA-HB; Fri, 19 May 2023 11:59:59 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From:
 Date; bh=09iWKHt8xgHcKIcB8ue9HPtGu+WsSQZJGd16Hmngwe0=; b=Z3O9BMhkiSTM3B3X8gcb
 emrwDpu8nQMJS+oZRVN3Mxl93lszGdt3Ul4+JXa2KCiB5+E7jvoyPeP6HlrFH4KNi/kdJN08qUQBI
 r16F/U9wCN20hdRU87sfv5mMOWq9GwY/O7PhbNHRXZogN8XVQ6WNKBNHkn/fboD/xZOpto2x1Jl9c
 qywSfbUYM089L621Zcq1F4kJKGV7syUWeO9a0cMFaIZh1l394nBXnfsnu72CdLDu5g0lkl5oKuxvZ
 qypIEeGIAxF5Zh1VlVsF74pfX0n9rW2AyEl7ej+1srvaJdK91pNw0idNC7CI/8+swi30GuQT5TL3E
 zoo25QnBxkTEtQ==;
Received: from [87.69.77.57] (helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1q02WM-0003bi-Hg; Fri, 19 May 2023 11:59:59 -0400
Date: Fri, 19 May 2023 19:00:13 +0300
Message-Id: <83ednctipe.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: balducci@HIDDEN, Stefan Monnier <monnier@HIDDEN>,
 Mattias =?iso-8859-1?Q?Engdeg=E5rd?= <mattiase@HIDDEN>
In-Reply-To: <4450.1684509068@HIDDEN> (balducci@HIDDEN)
Subject: Re: bug#63586: 29.x: dotimes (possible) problem
References: <4450.1684509068@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 63586
Cc: 63586 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: balducci@HIDDEN
> Date: Fri, 19 May 2023 17:10:44 +0200
> 
> the dotimes macro behaves differently in 29.x with respect to previous
> versions
> 
> Basically: changing the value of the loop variable in the body of
> dotimes does not seem to have any effect, where for versions <29.x it
> used to.
> 
> 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.

> The ability to jump out of the loop by pushing the loop variable over
> the upper limit is something that I happen to use in my scripts, so
> 29.x breaks them somehow
> 
> Of course, there are very many other equivalent ways to
> accomplish the same result, but I don't see why this one
> shouldn't be supported (any longer)
> 
> Is the changed behavior intentional? Am I missing some blatant point here?
> 
> AFAICS, changing the value of the loop variable from inside the loop
> body is supported by any other language which I know about

Adding Stefan and Mattias who made changes in dotimes recently.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63586; Package emacs. Full text available.

Message received at 63586 <at> debbugs.gnu.org:


Received: (at 63586) by debbugs.gnu.org; 19 May 2023 15:55:02 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 19 11:55:01 2023
Received: from localhost ([127.0.0.1]:57209 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1q02RZ-0001rn-Gp
	for submit <at> debbugs.gnu.org; Fri, 19 May 2023 11:55:01 -0400
Received: from mail1447c50.megamailservers.eu ([91.136.14.47]:34988
 helo=mail265c50.megamailservers.eu)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mattiase@HIDDEN>) id 1q02RX-0001qo-G5
 for 63586 <at> debbugs.gnu.org; Fri, 19 May 2023 11:55:00 -0400
X-Authenticated-User: mattiase@HIDDEN
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu;
 s=maildub; t=1684511692;
 bh=/Wpep1aUiJz4p6PCHALZKfVYchYUk4Z60bvrKECvHsU=;
 h=From:Subject:Date:Cc:To:From;
 b=nuXR+kdwUZcg2hx+C+J3YQDaU+x1gTDvTa6YrJP8/aaRjUvpvMAHxnMSbVp0C9Aba
 QsotMxDxojWgJwlyLv4AYwYOBfavmC8LWjXgbu8g3oP4ACD9t5q9+bycagHL2THjYE
 vDk6JZNth/6VLnitLGX0aTIHfUCrYCz03971Iq6E=
Feedback-ID: mattiase@HIDDEN
Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se
 [188.150.165.235]) (authenticated bits=0)
 by mail265c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 34JFsnt1086688; 
 Fri, 19 May 2023 15:54:51 +0000
From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= <mattiase@HIDDEN>
Content-Type: text/plain;
	charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\))
Subject: bug#63586: 29.x: dotimes (possible) problem
Message-Id: <D0DD1925-FF93-44EF-83D4-56E970922F9C@HIDDEN>
Date: Fri, 19 May 2023 17:54:48 +0200
To: balducci@HIDDEN
X-Mailer: Apple Mail (2.3654.120.0.1.15)
X-VADE-SPAMSTATE: clean
X-VADE-SPAMSCORE: -100
X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeihedgleegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffquffvqffrkfetpdfqfgfvpdfgpfggqdevhedtnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhtgfgggfukfffvefvofesthhqmhdthhdtvdenucfhrhhomhepofgrthhtihgrshcugfhnghguvghgnohrugcuoehmrghtthhirghsvgesrggtmhdrohhrgheqnecuggftrfgrthhtvghrnhepudekueejlefgkeejjeegudevvefhgfekudeggedvfeejfefgleetjedtvedvhfeunecukfhppedukeekrdduhedtrdduieehrddvfeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudekkedrudehtddrudeihedrvdefhedphhgvlhhopehsmhhtphgtlhhivghnthdrrghpphhlvgdpmhgrihhlfhhrohhmpehmrghtthhirghsvgesrggtmhdrohhrghdpnhgspghrtghpthhtohepgedprhgtphhtthhopegsrghlughutggtihesuhhnihhtshdrihhtpdhrtghpthhtohepieefheekieesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtphhtthhopehmohhnnhhivghrsehirhhordhumhhonhhtrhgvrghlrdgtrg
X-Origin-Country: SE
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: 63586
Cc: Eli Zaretskii <eliz@HIDDEN>, Stefan Monnier <monnier@HIDDEN>,
 63586 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

Hello Gabriele,

> changing the value of the loop variable in the body of dotimes does =
not seem to have any effect, where for versions <29.x it used to.

Prior to Emacs 29, the `dotimes` macro expanded to different code =
depending on whether lexical-binding was used or not, implicitly =
permitting your practice of altering the loop counter in code using =
dynamic binding.

However, the macro was probably never intended to be used that way, and =
your example does not work with lexical binding in any version as far as =
I can tell.

If you want to terminate your loop early, use catch/throw or a different =
loop construct altogether: while, named-let, or cl-loop, just to name a =
few.

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

Then you should learn more languages!

And you should use lexical-binding:t in all your elisp code. Always.






Information forwarded to bug-gnu-emacs@HIDDEN:
bug#63586; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 19 May 2023 15:11:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 19 11:11:16 2023
Received: from localhost ([127.0.0.1]:57113 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1q01lD-0000Tq-Un
	for submit <at> debbugs.gnu.org; Fri, 19 May 2023 11:11:16 -0400
Received: from lists.gnu.org ([209.51.188.17]:45998)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <balducci@HIDDEN>) id 1q01lB-0000Ti-SF
 for submit <at> debbugs.gnu.org; Fri, 19 May 2023 11:11:14 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <balducci@HIDDEN>) id 1q01lB-0006Z8-JF
 for bug-gnu-emacs@HIDDEN; Fri, 19 May 2023 11:11:13 -0400
Received: from dschgrazlin2.univ.trieste.it ([140.105.55.81]
 helo=dschgrazlin2.units.it) by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <balducci@HIDDEN>) id 1q01l9-0003ZM-KD
 for bug-gnu-emacs@HIDDEN; Fri, 19 May 2023 11:11:13 -0400
Received: from dschgrazlin2.units.it (loopback [127.0.0.1])
 by dschgrazlin2.units.it (8.17.1/8.17.1) with ESMTP id 34JFAihv004451
 for <bug-gnu-emacs@HIDDEN>; Fri, 19 May 2023 17:10:44 +0200
To: bug-gnu-emacs@HIDDEN
From: balducci@HIDDEN
Subject: 29.x: dotimes (possible) problem
X-Mailer: MH-E 8.6+git; nmh 1.8; Emacs 29.0.91
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <4449.1684509068.1@HIDDEN>
Date: Fri, 19 May 2023 17:10:44 +0200
Message-ID: <4450.1684509068@HIDDEN>
X-Greylist: inspected by milter-greylist-4.6.4 (dschgrazlin2.units.it
 [0.0.0.0]);
 Fri, 19 May 2023 17:10:44 +0200 (CEST) for IP:'127.0.0.1' DOMAIN:'loopback'
 HELO:'dschgrazlin2.units.it' FROM:'balducci@HIDDEN' RCPT:''
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.4
 (dschgrazlin2.units.it [0.0.0.0]); Fri, 19 May 2023 17:10:44 +0200 (CEST)
Received-SPF: pass client-ip=140.105.55.81; envelope-from=balducci@HIDDEN;
 helo=dschgrazlin2.units.it
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

hello

the dotimes macro behaves differently in 29.x with respect to previous
versions

Basically: changing the value of the loop variable in the body of
dotimes does not seem to have any effect, where for versions <29.x it
used to.

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 

The ability to jump out of the loop by pushing the loop variable over
the upper limit is something that I happen to use in my scripts, so
29.x breaks them somehow

Of course, there are very many other equivalent ways to
accomplish the same result, but I don't see why this one
shouldn't be supported (any longer)

Is the changed behavior intentional? Am I missing some blatant point here?

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

thank you very much in advance for any hint/feedback

ciao
-gabriele




Acknowledgement sent to balducci@HIDDEN:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#63586; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 19 May 2023 16:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.