Skip to content

Instantly share code, notes, and snippets.

@tacke758
Created April 20, 2014 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacke758/11103189 to your computer and use it in GitHub Desktop.
Save tacke758/11103189 to your computer and use it in GitHub Desktop.
coroutine implementation on scheme
(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