Skip to content

Instantly share code, notes, and snippets.

@zzkt
Created April 14, 2009 09:55
Show Gist options
  • Save zzkt/95092 to your computer and use it in GitHub Desktop.
Save zzkt/95092 to your computer and use it in GitHub Desktop.
;; 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