Looking for examples of "real" uses of continuations

Posted by Sébastien RoccaSerra on Stack Overflow See other posts from Stack Overflow or by Sébastien RoccaSerra
Published on 2008-08-29T08:07:58Z Indexed on 2010/05/05 0:18 UTC
Read the original article Hit count: 416

I'm trying to grasp the concept of continuations and I found several small teaching examples like this one from the Wikipedia article:

(define the-continuation #f)

(define (test)
  (let ((i 0))
    ; call/cc calls its first function argument, passing 
    ; a continuation variable representing this point in
    ; the program as the argument to that function. 
    ;
    ; In this case, the function argument assigns that
    ; continuation to the variable the-continuation. 
    ;
    (call/cc (lambda (k) (set! the-continuation k)))
    ;
    ; The next time the-continuation is called, we start here.
    (set! i (+ i 1))
    i))

I understand what this little function does, but I can't see any obvious application of it. While I don't expect to use continuations all over my code anytime soon, I wish I knew a few cases where they can be appropriate.

So I'm looking for more explicitely usefull code samples of what continuations can offer me as a programmer.

Cheers!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about language-agnostic