#lang racket (define p2-c #f) (define p2 (lambda () (call/cc (lambda (yield) (letrec ( (x 0) ; p is a continuously running program, that periodically yields and ; returns, but can be resumed by invoking continuation p2-c (p (lambda () (begin (set! x (+ x 1)) (display x) (newline) (call/cc (lambda (c) (set! p2-c c) (yield x))) (p) ))) ) ; start p (p) ; we shoud never get here "p is done" ))) )) (p2) ; what happens if you uncomment this ; (p2-c)