[plt-scheme] Continuations and (begin)
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.)
Try
(let ()
(call/cc
(lambda (k)
(set! r k)
#t))
(set! count-calls (+ count-calls 1)))
Matthew