coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 05 May 2021 18:30 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 06 May 2021 10:28 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Feeley 06 May 2021 14:26 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 06 May 2021 14:49 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Alexey Abramov 06 May 2021 15:32 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Nieper-Wißkirchen 06 May 2021 15:41 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 06 May 2021 16:28 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Nieper-Wißkirchen 06 May 2021 16:37 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 06 May 2021 16:48 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Nieper-Wißkirchen 06 May 2021 17:22 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Wolfgang Corcoran-Mathe 06 May 2021 19:12 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Nieper-Wißkirchen 06 May 2021 19:37 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Wolfgang Corcoran-Mathe 06 May 2021 21:54 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Nieper-Wißkirchen 07 May 2021 07:01 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Alex Shinn 07 May 2021 07:41 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Nieper-Wißkirchen 07 May 2021 08:35 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Alex Shinn 07 May 2021 08:41 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Nieper-Wißkirchen 07 May 2021 08:58 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Alex Shinn 07 May 2021 13:47 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 06 May 2021 19:36 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Lassi Kortela 06 May 2021 19:40 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche Boubekki 06 May 2021 21:25 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Marc Feeley 06 May 2021 17:07 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 06 May 2021 21:01 UTC
Re: coop - a concurrent ml-like wanna be (pre-SRFI) John Cowan 06 May 2021 21:25 UTC

Re: coop - a concurrent ml-like wanna be (pre-SRFI) Amirouche 06 May 2021 16:28 UTC

On 2021-05-06 17:41, Marc Nieper-Wißkirchen wrote:
> This needs delimited continuations to prevent space leaks, doesn't it?

What does "space leaks" means:

A) Memory is lost and can never be retrieved

Or

B) Use a lot of memory.

Here is the code I use:

   ;;
   ;; XXX: Inside call/pause, escapade-singleton allows to tell how
   ;; call/pause thunk continuation is called:
   ;;
   ;; - nominal case: thunk returned.
   ;;
   ;; - thunk called untangle-escapade, in that case escapade-singleton
   ;; is the first argument of the continuation of thunk inside
   ;; call/pause.
   ;;
   ;; escapade-singleton is a singleton, user code can not create it.
   ;;

   (define escapade-singleton '(escapade-singleton))

   ;; TODO: probably replace untangle with a box that contains the
   ;; escapade.
   (define (call/pause untangle thunk)
     (call-with-values (lambda ()
                         (call/1cc
                          (lambda (escape)
                            (assume (not (untangle-escapade untangle)))
                            (untangle-escapade! untangle escape)
                            (thunk))))
       (lambda args
         ;; TODO: use chibi's match
         ;; args may be the empty list if THUNK returns nothing.
         (if (and (pair? args) (eq? (car args) escapade-singleton))
             ;; XXX: The following code is the escapade handler! That
             ;; is always a proc and a continuation, because of how
             ;; pause is implemented. Racket call/ec has an optional
             ;; argument called handler that allows to change that
             ;; behavior.
             (let ((proc (cadr args))
                   (k (caddr args)))
               ;; call the procedure proc passed to untangle-escapade
               ;; with its continuation called k. That is, k, is what
               ;; follow escapade call inside THUNK. K will allow to
               ;; resume THUNK.
               (proc k))
             (apply values args)))))

   (define (pause untangle proc)
     (assume? untangle)
     ;; XXX: Capture the continuation and call it later, that is why it
     ;; use call/cc instead of call/1cc.
     (call/cc
      (lambda (k)
        ;; save escapade
        (define escapade (untangle-escapade untangle))
        ;; The escapade is a call/1cc continuation, no need to keep it
        ;; around, and it might lead to strange bugs.
        (untangle-escapade! untangle #f)
        ;; XXX: escapade is the continuation of a thunk inside
        ;; call/pause whereas k is the continuation of the caller of
        ;; pause inside thunk.

        ;; XXX: Continue with thunk's continuation inside call/pause as
        ;; known as escapade. Inside call/pause, proc and k are used to
        ;; build the pause handler.
        (escapade escapade-singleton proc k))))

> Unfortunately, these are not yet standardized.

Does it mean it is useless to work on coop?