[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: continuation passing in Emacs vs. JUST-THIS-ONE
From: |
Stefan Monnier |
Subject: |
Re: continuation passing in Emacs vs. JUST-THIS-ONE |
Date: |
Wed, 29 Mar 2023 15:00:38 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
> (defun await (future)
> (let (z)
> (while (eq 'EAGAIN (setq z (funcall future)))
> ;; TODO poke sit-for/io on yield? how?
> (sit-for 0.2))
> z))
This blocks, so it's the equivalent of `futur-wait`.
I.e. it's the thing we'd ideally never use.
> Assuming alet (async let) macro, which binds var when async process
> finishes with the value of its output:
I.e. what I called `future-let*`.
> (alet p1 '("which" "emacs")
> (when p1
> (alet p2 `("readlink" "-f" ,p1)
> (when p2
> (message "@@@ %s" p2)))))
Your syntax is more concise because it presumes all your async objects
run commands via `make-process`, but other than that it seems to be
doing basically the same as my code, yes.
> or even await async process inside async process:
>
> (await
> (async
> (alet p `("readlink" "-f" ,(await
> (async
> (alet p '("which" "emacs")
> (when p
> (yield p))))))
> (when p
> (yield p)))))
You use `await` which will block Emacs :-(
> I think this provides nicer interface for async code than futur.el and
> even comes with a working example.
I think you just reinvented the same thing, yes :-)
>> (concat foo (future-wait (futur-let* (...) ...)))
>
> Looking at other languages, they do it explicitly. The reason is, that
> one might want to save the future, do something else and await the
> future later at some point. Not await it immediately:
>
> (let ((future (futur-let* (...) ...)))
> ...
> (concat foo (future-wait future)))
I suspect that a better option would be instead of:
(let ((future (futur-let* (BINDS...) BODY)))
...
(concat foo (future-wait future)))
to use
(futur-let* (BINDS...
(s BODY))
(concat foo s))
The difference is that it doesn't return a string but a `futur`, so if
you want the string you need to use `future-let*` or `futur-wait`.
The advantage is that you still have the choice to use `future-let*`
rather than `futur-wait`.
Stefan
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, (continued)
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, tomas, 2023/03/12
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Karthik Chikmagalur, 2023/03/14
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Jim Porter, 2023/03/14
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Stefan Monnier, 2023/03/15
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Tomas Hlavaty, 2023/03/16
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Stefan Monnier, 2023/03/16
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Jim Porter, 2023/03/17
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Tomas Hlavaty, 2023/03/25
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Tomas Hlavaty, 2023/03/26
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Tomas Hlavaty, 2023/03/28
- Re: continuation passing in Emacs vs. JUST-THIS-ONE,
Stefan Monnier <=
- Re: continuation passing in Emacs vs. JUST-THIS-ONE, Stefan Monnier, 2023/03/29
Re: continuation passing in Emacs vs. JUST-THIS-ONE, Richard Stallman, 2023/03/13
Re: continuation passing in Emacs vs. JUST-THIS-ONE, miha, 2023/03/16
Re: continuation passing in Emacs vs. JUST-THIS-ONE, Tomas Hlavaty, 2023/03/25
Re: continuation passing in Emacs vs. JUST-THIS-ONE, Tomas Hlavaty, 2023/03/26