我想讀這個代碼:這個Scheme列表迭代器如何使用call-with-current-continuation?
(define list-iter
(lambda (a-list)
(define iter
(lambda()
(call-with-current-continuation control-state)))
(define control-state
(lambda (return)
(for-each
(lambda (element)
(set! return (call-with-current-continuation
(lambda (resume-here)
(set! control-state resume-here)
(return element)))))
a-list)
(return 'list-ended)))
iter))
任何人都可以解釋這個例子如何call-with-current-continuation
作品?
由於
關於SO可能還有其他的「什麼是call/cc」問題的重複。我能找到的最具規範和顯然有用的人:http://stackoverflow.com/questions/612761/what-is-call-cc。 – amalloy 2011-04-12 03:19:03
我想到了這個具體的例子,使用類似「yield」的模式,足以證明自己的價值。不過,也許它應該被重新命名。 – acfoltzer 2011-04-12 03:23:09