whalesong/tests/more-tests/sk-generator-2.rkt
2011-08-30 02:10:03 -04:00

32 lines
837 B
Racket

#lang planet dyoo/whalesong/base
(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")))))
(define g2 (make-gen (lambda (ret)
(begin
(ret 1)
(ret 2)
(ret 3)))))
(g1)
(g1)
(g1)
(g2)
(g2)
(g2)