[racket-dev] continuation weirdness

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Wed Aug 11 15:58:03 EDT 2010

I came across some oddity under DrRacket involving continuations.  If
I have the following in my definitions window:


#lang racket
(define (make-gen gen)
 (let ([cont (box #f)])
   (lambda ()
     (call/cc (lambda (caller)
                (if (unbox cont)
                    ((unbox cont) caller)
                    (gen (lambda (v)
                           (call/cc (lambda (gen-k)
                                        (set-box! cont gen-k)
                                        (caller v))))))))))))
(define g1 (make-gen (lambda (return)
                        (return "a")
                        (return "b")
                        (return "c")))))


then when I call (g1) in the interactions window, I see the following:

> (g1)

where the print-values display of the continuation function appears to
be printing twice.  I guess I'm trying to understand what DrScheme is
doing, well enough that I can duplicate this behavior in WeScheme, but
I'm a bit baffled.

Posted on the dev mailing list.