[plt-scheme] Understanding continuations

From: Jos Koot (jos.koot at telefonica.net)
Date: Sat Jul 19 05:32:29 EDT 2008

BTW it is right that every time you call a continuation you can pass it 
another argument (and if the continuation awaits a multiple value as many 
arguments as values expected)
The important thing to keep in mind is at what point in the program the 
evaluation will be continued.

You may want to look to the following example too:

#lang scheme
(require scheme/control)
(define cont #f)
(define (foo)
 (prompt (call-with-composable-continuation
   (lambda (arg-cont)
     (set! cont arg-cont)
     13))))
 (+ 1 2 3 (foo))
 (cont 111)


Jos
----- Original Message ----- 
From: "Grant Rettke" <grettke at acm.org>
To: "PLT-list" <plt-scheme at list.cs.brown.edu>
Sent: Saturday, July 19, 2008 7:44 AM
Subject: [plt-scheme] Understanding continuations


> I'm trying to visualize and understand continuations (this part of the
> work in another thread [Confusing continuation behavior (a question
> about)]).
>
> If I write:
>
> #lang scheme
> (define cont #f)
> (define (foo)
>  (call/cc
>   (lambda (arg-cont)
>     (set! cont arg-cont)))
>  13)
> (+ 1 2 3 (foo))
>
> Could I visualize the continuation as?
>
> (lambda (argument)
>  (+ 1 2 3 13))
>
> If I write:
>
> #lang scheme
> (define cont #f)
> (define (foo)
>  (call/cc
>   (lambda (arg-cont)
>     (set! cont arg-cont)
>     13)))
> (+ 1 2 3 (foo))
>
> Could I visualize the continuation as?
>
> (lambda (argument)
>  (+ 1 2 3 argument))
>
> The difference between the two is this:
>
> 1. In the first one, the saved continuation 'cont' will always have
> the same value; that of the current continuation with the value of 13
> passed in to it. Every time that continuation is applied the result
> will be the same. It is like memoization.
>
> 2. In the second one, the continuation is awaiting a value of the
> function foo (or it is waiting for the expression of the call/cc
> block). So at any other point, that continuation could be passed
> "something else".
>
> In the first one, "what happens next" could never change, because it
> has been determined. In the second one, "what happens next" could
> change, because the continuation is still waiting for a value.
>
> Is that right?
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme 



Posted on the users mailing list.