我在http://community.schemewiki.org/?call-with-current-continuation中查看以下关于协程的示例:
(define (hefty-computation do-other-stuff)
(let loop ((n 5))
(display "Hefty computation: ")
(display n)
(newline)
(set! do-other-stuff (call/cc do-other-stuff)) ; point A
(display "Hefty computation (b)")
(newline)
(set! do-other-stuff (call/cc do-other-stuff))
(display "Hefty computation (c)")
(newline)
(set! do-other-stuff (call/cc do-other-stuff))
(if (> n 0)
(loop (- n 1)))))
Run Code Online (Sandbox Code Playgroud)
多余的工作:
;; notionally displays a clock
(define (superfluous-computation do-other-stuff)
(let loop ()
(for-each (lambda (graphic)
(display graphic)
(newline)
(set! do-other-stuff (call/cc do-other-stuff)))
'("Straight up." "Quarter after." "Half past." "Quarter til.")) …Run Code Online (Sandbox Code Playgroud)