Created
April 14, 2009 09:55
-
-
Save zzkt/95092 to your computer and use it in GitHub Desktop.
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
;; http://repository.readscheme.org/ftp/papers/PLoP2001_dferguson0_1.pdf | |
(define coroutine-maker | |
(lambda (proc) | |
(let ((saved-continuation '())) | |
(let ((update-continuation! (lambda (v) | |
(display "updating") | |
(set! saved-continuation v)))) | |
(let ((resumer (resume-maker update-continuation!)) | |
(first-time #t)) | |
(lambda (value) | |
(if first-time | |
(begin | |
(set! first-time #f) | |
(proc resumer value)) | |
(saved-continuation value)))))))) | |
(define resume-maker | |
(lambda (update-proc!) | |
(lambda (next-coroutine value) | |
(let ((receiver (lambda (continuation) | |
(update-proc! continuation) | |
(next-coroutine value)))) | |
(call-with-current-continuation receiver))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment