guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Continuation sets and order-independency


From: David Kastrup
Subject: Re: Continuation sets and order-independency
Date: Fri, 13 Jan 2012 21:54:13 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Mark H Weaver <address@hidden> writes:

> I'm still not entirely clear on what you want,

Well, I said there were elements missing in the picture, so it is not
like I am entirely clear on it myself.

> but perhaps you're looking for delimited continuations, a.k.a
> composable continuations, partial continuations, or _prompts_.  They
> are not yet part of standard Scheme, but some advanced implementations
> have them, including Guile 2.0.  (They are not available in Guile
> 1.8).
>
>   http://www.gnu.org/software/guile/manual/html_node/Prompts.html
>
> I've attached a small example module that might do what you want.
> Here's an example session, starting with the highest-level syntax:
>
>   scheme@(guile-user)> ,use (mhw suspendable)
>   scheme@(guile-user)> (%% list 1 2 3 (begin (suspend) 4) 5)
>   $1 = ((completed 1) (completed 2) (completed 3) (suspended 
> #<partial-continuation 10541cd0>) (completed 5))
>   scheme@(guile-user)> (map final-values $1)
>   $2 = (1 2 3 4 5)
>   scheme@(guile-user)> 
>
> This is based on some lower-level primitives: (suspendable <expr> ...)
> evaluates the expressions and returns a <suspension>.

I assume that the above list could contain more than a single call of
(suspend).

> Basically what the high-level `%%' syntax does is to call a procedure,
> but automatically evaluate all of its operands as parallel suspendable
> computations.  The suspensions are passed to the procedure, which may
> resume them (or ask for their final-values) as desired.
>
> (Actually, the operator is evaluated in the same way as the operands, in
> the tradition of Scheme.)
>
> For example, (%% list 1 2 3 (begin (suspend) 4) 5) expands to:
>
>   (call-with-values
>       (lambda () (parallel (suspendable list)
>                            (suspendable 1)
>                            (suspendable 2)
>                            (suspendable 3)
>                            (suspendable (begin (suspend) 4))
>                            (suspendable 5)))
>     (lambda (proc . args)
>       (apply (final-values proc) args)))
>
> Is this what you're looking for, or something close to it?

Not really.  The above uses "parallel", and if I remember correctly,
this implies multi-threaded execution and true asynchronicity
(preemptive scheduling).  I was rather thinking about avoiding the
overhead and work things off serially but without stopping if one part
runs into suspension, but rather commencing with another part of the
expression until every branch has run into suspension.  Effectively
multithreading without preemption and the associated costs.

-- 
David Kastrup




reply via email to

[Prev in Thread] Current Thread [Next in Thread]