[plt-scheme] Continuations and (begin)

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Feb 7 11:48:00 EST 2009

Do you mean

    (define (state) (call/cc (lambda (x) x))) ;; that's the old name  
from some 1970's or early 1980's language that I can't recall

Try programming with it to find out why call/cc is so much better. --  
Matthias




On Feb 7, 2009, at 10:13 AM, James Coglan wrote:

>
>
> 2009/2/7 Matthew Flatt <mflatt at cs.utah.edu>
> 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.)
>
> Thanks. Just out of curiosity, is there a function that simply  
> returns the current continuation without jumping to another  
> function using (call/cc)?
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090207/b4dca27b/attachment.html>

Posted on the users mailing list.