[racket-dev] continuation weirdness
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)
(begin
(set-box! cont gen-k)
(caller v))))))))))))
(define g1 (make-gen (lambda (return)
(begin
(return "a")
(return "b")
(return "c")))))
(g1)
(g1)
(g1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
then when I call (g1) in the interactions window, I see the following:
;;;;;;;;;;;;;;;;;;;;;;;;;
> (g1)
#<continuation>
#<continuation>
;;;;;;;;;;;;;;;;;;;;;;;;;
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.