unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: "balducci@dschgrazlin2.units.it" <balducci@dschgrazlin2.units.it>,
	"63588@debbugs.gnu.org" <63588@debbugs.gnu.org>
Subject: bug#63588: 29.x: dotimes (possible) problem
Date: Fri, 19 May 2023 15:42:36 +0000	[thread overview]
Message-ID: <SJ0PR10MB548828FC5EA33DB442848C77F37C9@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <30876.1684486510@dschgrazlin2.units.it>

> 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.
...
> 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

No, it's not.

From CLTL2 [*]:

  "Altering the value of var in the body of the loop
   (by using setq, for example) will have unpredictable,
   possibly implementation-dependent results. A Common
   Lisp compiler may choose to issue a warning if such
   a variable appears in a setq."

That allows an implementation of CL to define some
particular behavior in this regard.  But it also says
that if it does, and if your CL code depends on that
behavior, then it won't necessarily be portable to
other CL implementations.

It's unfortunate that if this Elisp change isn't
backward compatible.  That's indeed a consideration.
But it's wise for your code not to depend on being
able to change the loop variable and get any
meaningful resulting behavior.

Both in CL and Elisp `dotimes' lets you use RETURN
to break out of the loop.  That should speak to one
of your use cases, at least.

(dotimes (ii  100  "*********")
  (when (= 4 ii) (return "4444444444")))

CLTL2 says this:

  "An explicit return statement may be used to
   terminate the loop and return a specified value."

But I don't see where this is documented for Elisp.
Maybe it is documented somewhere.  Should be.
___

[*] https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node89.html





  reply	other threads:[~2023-05-19 15:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19  8:54 bug#63588: 29.x: dotimes (possible) problem balducci
2023-05-19 15:42 ` Drew Adams [this message]
2023-05-19 16:07 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2023-05-19 15:10 bug#63586: " balducci
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
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=SJ0PR10MB548828FC5EA33DB442848C77F37C9@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=63588@debbugs.gnu.org \
    --cc=balducci@dschgrazlin2.units.it \
    /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).