[plt-scheme] Understanding continuations

From: Filipe Cabecinhas (filcab at gmail.com)
Date: Wed Jul 23 02:35:39 EDT 2008

On 19 Jul, 2008, at 23:08, Anton van Straaten wrote:

> Grant Rettke wrote:
>> 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))
>
> You could, but you should be aware that this is an optimized version  
> of the continuation.  The questions you've asked below might be  
> answered more easily and precisely if you had a more detailed  
> representation of the continuation, which at the very least should  
> include a reference to 'argument' (other than its binding).  Where  
> does that reference belong?

So, I suppose the continuation should be something like:
(lambda (argument)  ;; Continuation that just returns to the toplevel
   ((lambda (other-argument)  ;; Call to plus with the result of foo
      (+ 1 2 3 other-argument))
    ((lambda (inner-argument)  ;; the rest of the foo function
       inner-argument
       13))))

effectively turning the program inside out. Or am I misunderstanding  
what you want to say?


   - Filipe Cabecinhas





Posted on the users mailing list.