小编hxn*_*sun的帖子

方案:嵌套调用/ cc如何为协程工作?

我在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)

scheme callcc coroutine continuation

5
推荐指数
1
解决办法
619
查看次数

标签 统计

callcc ×1

continuation ×1

coroutine ×1

scheme ×1