Created
April 20, 2014 02:16
-
-
Save tacke758/11103189 to your computer and use it in GitHub Desktop.
coroutine implementation on scheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define proc1 '()) | |
(define proc2 '()) | |
(define (coroutine1) | |
(define (yield-for next-cnt) | |
(call/cc (lambda (cnt) | |
(set! proc1 cnt) | |
(next-cnt)))) | |
(define (setup) | |
(call/cc (lambda (cnt) | |
(set! proc1 cnt) | |
(coroutine2)))) | |
(setup) | |
(for-each (lambda (i) | |
(print "cor1:" i) | |
(if (not (eq? i 5)) | |
(yield-for proc2))) | |
(list 1 2 3 4 5))) | |
(define (coroutine2) | |
(define (yield-for next-cnt) | |
(call/cc (lambda (cnt) | |
(set! proc2 cnt) | |
(next-cnt)))) | |
(for-each (lambda (i) | |
(print "cor2:" i) | |
(yield-for proc1)) | |
(list 1 2 3 4 5))) | |
(coroutine1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment