#lang racket (define R1-c (lambda (arg) (display "Error R1-c not defined yet") )) (define R2-c (lambda (arg) (display "Error R2-c not defined yet") )) (define R1 (lambda () (call/cc (lambda (break) (let ((i 5)) ; capture our continuation, but bail out of further execution (call/cc (lambda (k) (set! R1-c k) (break "R1-c defined"))) ; ; The next time the-continuation is called, we start here. (display "R1 - I am back ") ; we are mutating the state inside the continuation, so we get ; a new result everytime we invoke the continuation (set! i (- i 1)) (display i) (newline) (if (> i 0) (R2-c 0) i) ) ) ) )) (define R2 (lambda () (call/cc (lambda (break) (let ((i 5)) ; capture our continuation, but bail out of further execution (call/cc (lambda (k) (set! R2-c k) (break "R2-c defined"))) ; ; The next time the-continuation is called, we start here. (display "R2 - I am back ") ; we are mutating the state inside the continuation, so we get ; a new result everytime we invoke the continuation (set! i (+ i 1)) (display i) (newline) (R1-c 0) i) ) ) ) ) ; to start things off we need to (R1) (R2) (R1-c) ; or (R2-c) if you want R2 to go first