unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Spencer Baugh <sbaugh@janestreet.com>
Cc: emacs-devel@gnu.org
Subject: Re: unwind-protect within while-no-input
Date: Thu, 09 May 2024 08:46:10 +0300	[thread overview]
Message-ID: <86edab8rml.fsf@gnu.org> (raw)
In-Reply-To: <ier34qsqf15.fsf@janestreet.com> (message from Spencer Baugh on Wed, 08 May 2024 15:28:38 -0400)

> From: Spencer Baugh <sbaugh@janestreet.com>
> Date: Wed, 08 May 2024 15:28:38 -0400
> 
> >> How does my-function run the unwind-forms when it is interrupted by
> >> while-no-input?
> >
> > How can a function cause its caller to do anything at all?  It can't.
> > If the caller wants to make sure some unwind-forms will always run
> > after my-function either returns locally or exits non-locally, the
> > caller needs to arrange for that.
> 
> I don't want to run the unwind forms "after" my-function returns or
> exits.  I want them to run wherever they are inside my-function, just
> like a normal unwind-protect.
> 
> Let me try to explain again what I want: I want a completely normal
> unwind-protect, exactly how unwind-protect works normally:
> 
>   (unwind-protect BODYFORM UNWINDFORMS...)
>   
>   Do BODYFORM, protecting with UNWINDFORMS.
>   If BODYFORM completes normally, its value is returned
>   after executing the UNWINDFORMS.
>   If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
> 
> Except that I want the UNWINDFORMS to not be interrupted by a
> *surrounding* while-no-input or quit or any other kind of nonlocal exit.
> 
> Is there any way to do that?  ("Move the while-no-input inside the
> unwind-protect" is not an answer, because then it's not a *surrounding*
> while-no-input anymore)

IMO, you are trying to solve a problem that is impossible to solve in
general: a function cannot be responsible for the environment in which
it is called.  You keep talking about while-no-input, but that's just
an example; there's a virtually infinite number of ways the caller of
your function can call it in a way that thwarts any attempt of yours
to prevent non-local exits.  Given enough motivation and effort (and
reliance on the internal implementation details), you could perhaps
fix that single case of calling the function inside while-no-input,
but that will not solve all the rest.

The correct solution to these problems is to document the requirements
of your function from the callers, and let the callers deal with that
according to their needs.  (I suspect that in the case that bothers
you, you yourself are that caller, which makes it easier to implement
such protocols.)

Btw, you never explained why you are bothered specifically by
while-no-input.  Nor did you describe the problem.  Instead, you
describe a solution ("I want a completely normal unwind-protect..."),
and ask us to program such a solution for you without understanding
the problem or the reason why you want to solve it with a "normal
unwind-protect".  That is a sure way of making this discussion very
frustrating, if not downright useless.  Look how many messages this
thread has already amassed, and how many solutions were proposed, only
to be rejected by you for some reason that was never stated before.



  reply	other threads:[~2024-05-09  5:46 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 12:45 unwind-protect within while-no-input Spencer Baugh
2024-05-07 18:05 ` Spencer Baugh
2024-05-07 18:49   ` Eli Zaretskii
2024-05-07 19:43     ` Spencer Baugh
2024-05-08  3:59       ` Po Lu
2024-05-08 11:42         ` Michael Heerdegen via Emacs development discussions.
2024-05-08 11:47           ` Michael Heerdegen via Emacs development discussions.
2024-05-08 13:44             ` Spencer Baugh
2024-05-08 16:13               ` Michael Heerdegen via Emacs development discussions.
2024-05-08 17:18                 ` Spencer Baugh
2024-05-08 20:43                   ` Michael Heerdegen via Emacs development discussions.
2024-05-09 12:57                     ` Spencer Baugh
2024-05-09 14:13                       ` Michael Heerdegen via Emacs development discussions.
2024-05-08 12:12           ` Eli Zaretskii
2024-05-08 12:36             ` Michael Heerdegen via Emacs development discussions.
2024-05-08 11:52       ` Eli Zaretskii
2024-05-08 13:57         ` Spencer Baugh
2024-05-08 14:18           ` Eli Zaretskii
2024-05-08 14:38             ` Spencer Baugh
2024-05-08 15:06               ` Eli Zaretskii
2024-05-08 15:14                 ` Spencer Baugh
2024-05-08 18:51                   ` Eli Zaretskii
2024-05-08 19:28                     ` Spencer Baugh
2024-05-09  5:46                       ` Eli Zaretskii [this message]
2024-05-09 13:07                         ` Spencer Baugh
2024-05-09 17:41                           ` Dmitry Gutov
2024-05-11  9:48                           ` Eli Zaretskii
2024-05-11 10:37                             ` Eshel Yaron
2024-05-11 10:42                           ` Zhengyi Fu
2024-05-11 21:45                             ` Dmitry Gutov
2024-05-11 22:08                               ` Daniel Mendler via Emacs development discussions.
2024-05-12  1:59                                 ` Dmitry Gutov
2024-05-12  8:50                                   ` Daniel Mendler via Emacs development discussions.
2024-05-12 11:49                                     ` Dmitry Gutov
2024-05-14 21:30                           ` Dmitry Gutov
2024-05-26  2:49                             ` Stefan Monnier via Emacs development discussions.
2024-05-26 15:36                               ` Dmitry Gutov
2024-05-26 18:00                                 ` Stefan Monnier
2024-05-26 22:56                                   ` Dmitry Gutov
2024-05-29  0:39                                     ` Stefan Monnier
2024-05-29  1:17                                       ` Dmitry Gutov
2024-05-08 20:34                     ` Michael Heerdegen via Emacs development discussions.
2024-05-08 16:17               ` Michael Heerdegen via Emacs development discussions.
2024-05-26  2:47   ` Stefan Monnier via Emacs development discussions.
2024-05-26  4:36     ` Stefan Monnier
2024-05-26  4:55     ` Eli Zaretskii
2024-05-26 18:12       ` Stefan Monnier

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=86edab8rml.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=sbaugh@janestreet.com \
    /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).