Last active
March 14, 2017 03:56
-
-
Save shirok/c470de4c1820080e643505c71d880806 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
| (define (f) (call/cc (lambda (k) ...)) (print "baz")) | |
| (define (g) (f) (print "foo")) | |
| (define (h) (g) (a) (print "bar")) | |
| (define (a) ...) | |
| printが入れてあるのはTCOで話をややこしくしないため。 | |
| (h) を呼び出して実行が進み、(a)に入った時点で、スタックフレームだけ考えると | |
| [トップレベル] <- [hのスタックフレーム] <- [aのスタックフレーム] | |
| だけど、f内で捕まえられたkは | |
| [トップレベル] <- [hのスタックフレーム] <- [gのスタックフレーム] <- [fのスタックフレーム] | |
| というアクティベーションチェーンを保持してる。つまり全体で見るとこんな感じで木になる。 | |
| /--- [a] (現在の継続) | |
| [トップレベル] <-- [h] ---* | |
| \--- [g] --- [f] (k) | |
| 継続がいくつあっても同じ。コルーチンは木の枝を渡り歩くイメージ。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment