[plt-scheme] Understanding continuations

From: Grant Rettke (grettke at acm.org)
Date: Sun Jul 20 21:37:33 EDT 2008

> When (lambda (value) (+ 1 2 3 value)) is called, where does it return the value?

If the continuations were passed explicitly, I think it would look
like this (I also bound the result of calling foo):

#lang scheme
(define cont #f)
(define (foo arg-cont)
  (set! cont arg-cont)
  (arg-cont 13))

(let ([value (foo (lambda (value) (+ 1 2 3 value)))])
  (printf "~a~n" value))

When the continuation returns, it jumps back into the control flow of
the top-level-execution, in the environment where cont and foo are
bound, but 'value' is not yet bound. Is that correct? It is as though
a bigger function exists at the top level, for which some names are
bound, and the continuation calls into that function, providing the
object for value. It is that idea that I read about (tail-transfer),
where you never return, you just keep going to the "next place",
conceptually at least. In the let block, conceptually what has to
happen is that it is actually another function. I'm on thin ice here,
am I going in the right direction?


Posted on the users mailing list.