[plt-scheme] Continuations and (begin)

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Feb 7 08:43:00 EST 2009

At Sat, 7 Feb 2009 13:34:38 +0000, James Coglan wrote:
> (begin
>   (call/cc
>     (lambda (k)
>       (set! r k)
>       #t))
>   (set! count-calls (+ count-calls 1)))
> (r #t) (r #t) (r #t)
> I would expect count-calls to equal 4 after this, but it equals 1. The
> continuation, from what little I've read about this, should look like:
> ([#procedure] [#hole] (set! count-calls (+ count-calls 1)))

The body of a top-level `begin' is spliced into the top-level sequence,
so the `begin' above doesn't usefully group the two expressions. (To
put it another way, a top-level `begin' wraps a prompt around each of
its sub-expressions.)


 (let ()
     (lambda (k)
       (set! r k)
   (set! count-calls (+ count-calls 1)))


Posted on the users mailing list.