all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tomas Hlavaty <tom@logand.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Jim Porter <jporterbugs@gmail.com>,
	Karthik Chikmagalur <karthikchikmagalur@gmail.com>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: continuation passing in Emacs vs. JUST-THIS-ONE
Date: Wed, 12 Apr 2023 01:07:32 +0200	[thread overview]
Message-ID: <87v8i2dnm3.fsf@logand.com> (raw)
In-Reply-To: <jwvr0sqkwvo.fsf-monnier+emacs@gnu.org>

On Tue 11 Apr 2023 at 16:22, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> It is useful to acknowledge, that there are 3 different use-cases:
>> a) asynchronous processes
>> b) threads
>> c) iter
>
> I can't see how `iter` would be a use case for futures.

It makes it easy to implement async/await without the need for
asynchronous processes or threads.

>> My impression was that futur.el was trying to address a) and b) but
>> now you say it does address a) only.  That is rather limited.
>
> Looking at existing code, iter and threads are virtually never used,
> so from where I stand it seems to cover the 99% cases.

Strange that futur.el is "primarily concerned with making it easier to
write asynchronous code" but limits itself to asynchronous processes
only.

I am also "concerned with making it easier to write asynchronous code"
but I explore various options available in Emacs so that the result
would not end up with some patological flaw due to specifics of
asynchronous processes.

I do not know how useable threads in Emacs are at the moment,
but they are already there and the examples I tried worked well.
If they are not useable now, I hope they will be useable in the future.
(Pun intended:-)

And I do not think I am the only one:

   From: Po Lu <luangruo@yahoo.com>
   Date: Mon, 03 Apr 2023 12:03:17 +0800
   id:87mt3pr4sa.fsf@yahoo.com

   I have not looked carefully at this thread, but I would hope that if
   people are discussing a way to add multiprocessing to Emacs, we
   settle on separate threads of execution executing in parallel, with
   all the interlocking necessary to make that happen, like in most Unix
   thread implementations.

It would be a shame not to consider them.
Especially when that use-case is easy to implement and
works as demonstrated with the promise-pipelining-server3 example.

>>>> No, the iter case does map directly to futures:
>>>>
>>>> (await
>>>>  (async-iter
>>>>    (let ((a (async-iter
>>>>               (message "a1")
>>>>               (await-iter (sleep-iter3 3))
>>>>               (message "a2")
>>>>               1))
>>>>          (b (async-iter
>>>>               (message "b1")
>>>>               (let ((c (async-iter
>>>>                          (message "c1")
>>>>                          (await-iter (sleep-iter3 3))
>>>>                          (message "c2")
>>>>                          2)))
>>>>                 (message "b2")
>>>>                 (+ 3 (await-iter c))))))
>>>>      (+ (await-iter a) (await-iter b)))))
>>>
>>> I must say I don't understand this example: in which sense is it using
>>> "iter"?  I don't see any `iter-yield`.
>>
>> await-iter and async-iter macros are using iter under the hood.
>
> The point of `iter` is to provide something that will iterate through
> a sequence of things.  Here I don't see any form of iteration.

I sent the whole self-contained example.  The iteration happens in the
top-level loop (see await-in-background).

> You seem to use your `iter`s just as (expensive) thunks (futures).

What do you mean?
Are thunks expensive?
More expensive than cl-struct and CLOS in futur.el?
Surely it's the other way round.

In the use-case of iter (no asynchronous processes or threads), iter is
used to do cps rewriting needed by async-iter.

> Maybe what you mean by "iter" is the use of CPS-translation
> (implemented by `generator.el`)?

Yes, iter provides the sequence of steps needed to compute the whole
async-iter expression.  See

   (iter-make (iter-yield (progn ,@body)))

in async-iter macro.

>>> Of course.  You could do something like
>>>
>>>       (futur-let*
>>>           ((a (futur-let* ((_ <- (futur-process-make
>>>                                  :command '("sleep" "9"))))
>>>                  9))
>>>            (b (futur-let* ((_ <- (futur-process-make
>>>                                  :command '("sleep" "8"))))
>>>                  8))
>>>            (a-val <- a)
>>>            (b-val <- b))
>>>         (message "Result = %s" (+ a-val b-val))))
>>
>> So will futur.el take 9sec or 17sec?
>
> 9 secs, of course: the above creates 2 futures and emits the message
> when they're both done.  Since those futures are executed in
> subprocesses, they execute concurrently.

Good.  So I don't understand your remark about parallelism.  Maybe I
should believe you that it would take 9sec, but I would rather verify
that by myself because being "executed in subprocesses" does not
necessarily mean "they execute concurrently".

>>> Similarly the "intended return value" of a process will depend on what
>>> the process does.  In some cases it will be the stdout, but I see no
>>> reason to restrict my fundamental function to such a choice.
>> This overgeneralized thinking is beyond usefulness and harmfully leads
>> to the problem of how to maintain state.
>
> While I do like to over-generalize, in this case, there is no
> generalization involved.  The code is the simple result of a thin
> wrapper around the existing `make-process` to make it obey the
> `futur.el` API.  So if it's overgeneralized, it's not my fault, it's
> `make-process`s :-)

Not really, make-process is general because it covers many use-cases.
Futures are quite specific.  Anything beyond the specifics cause issues.



  reply	other threads:[~2023-04-11 23:07 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-11 12:53 continuation passing in Emacs vs. JUST-THIS-ONE Thomas Koch
2023-03-12  1:45 ` Jim Porter
2023-03-12  6:33   ` tomas
2023-03-14  6:39   ` Karthik Chikmagalur
2023-03-14 18:58     ` Jim Porter
2023-03-15 17:48       ` Stefan Monnier
2023-03-17  0:17         ` Tomas Hlavaty
2023-03-17  3:08           ` Stefan Monnier
2023-03-17  5:37             ` Jim Porter
2023-03-25 18:42             ` Tomas Hlavaty
2023-03-26 19:35               ` Tomas Hlavaty
2023-03-28  7:23                 ` Tomas Hlavaty
2023-03-29 19:00                 ` Stefan Monnier
2023-04-03  0:39                   ` Tomas Hlavaty
2023-04-03  1:44                     ` Emanuel Berg
2023-04-03  2:09                     ` Stefan Monnier
2023-04-03  4:03                       ` Po Lu
2023-04-03  4:51                         ` Jim Porter
2023-04-10 21:47                       ` Tomas Hlavaty
2023-04-11  2:53                         ` Stefan Monnier
2023-04-11 19:59                           ` Tomas Hlavaty
2023-04-11 20:22                             ` Stefan Monnier
2023-04-11 23:07                               ` Tomas Hlavaty [this message]
2023-04-12  6:13                                 ` Eli Zaretskii
2023-04-17 20:51                                   ` Tomas Hlavaty
2023-04-18  2:25                                     ` Eli Zaretskii
2023-04-18  5:01                                       ` Tomas Hlavaty
2023-04-18 10:35                                       ` Konstantin Kharlamov
2023-04-18 15:31                                         ` [External] : " Drew Adams
2023-03-29 18:47               ` Stefan Monnier
2023-04-17  3:46                 ` Lynn Winebarger
2023-04-17 19:50                   ` Stefan Monnier
2023-04-18  2:56                     ` Lynn Winebarger
2023-04-18  3:48                       ` Stefan Monnier
2023-04-22  2:48                         ` Lynn Winebarger
2023-04-18  6:19                     ` Jim Porter
2023-04-18  9:52                       ` Po Lu
2023-04-18 12:38                         ` Lynn Winebarger
2023-04-18 13:14                         ` Stefan Monnier
2023-04-19  0:28                           ` Basil L. Contovounesios
2023-04-19  2:59                             ` Stefan Monnier
2023-04-19 13:25                               ` [External] : " Drew Adams
2023-04-19 13:34                                 ` Robert Pluim
2023-04-19 14:19                                   ` Stefan Monnier
2023-04-21  1:33                                     ` Richard Stallman
2023-04-19  1:11                           ` Po Lu
2023-04-17 21:00                   ` Tomas Hlavaty
2023-03-14  3:58 ` Richard Stallman
2023-03-14  6:28   ` Jim Porter
2023-03-16 21:35 ` miha
2023-03-16 22:14   ` Jim Porter
2023-03-25 21:05 ` Tomas Hlavaty
2023-03-26 23:50 ` Tomas Hlavaty

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

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

  git send-email \
    --in-reply-to=87v8i2dnm3.fsf@logand.com \
    --to=tom@logand.com \
    --cc=emacs-devel@gnu.org \
    --cc=jporterbugs@gmail.com \
    --cc=karthikchikmagalur@gmail.com \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.