News for hackers. Stuff that matters.
Re:Why Are Continuations So Confusing, and What Do They Real... by jcl on Friday March 14, 2008 @01:12PM (#136919)
What Scheme are you running this with? I tried your code in DrScheme, and it prints "Hello, World!" exactly once, with no error, no infinite loop. I'm not sure why, but I expect it has something to do with the semantics of "begin" (maybe a bug in DrScheme?); you can make the code work in DrScheme as you describe if you use "let" instead of "begin":

  (let ((cont #f)) 
    (set! cont (call/cc (lambda (k) k)))
    (print "Hello, world!")
    (cont #f))
You can get an infinite loop by changing where the variable is set:

  (let ((cont #f)) 
    (call/cc (lambda (k) (set! cont k)))
    (print "Hello, world!")
    (cont #f))

There are no comments on this comment yet.