這一頁放雜物。
-
-
- 此地無銀三百兩。試圖轉移焦點。
有趣議題
術語
-
-
- Continuation 是一個用來表示程序控制流的抽象結構。
-
Functional and logic compilers often use CPS as an intermediate representation where a compiler for an imperative or procedural programming language would use static single assignment form (SSA). SSA is formally equivalent to a subset of CPS (excluding non-local control flow, which does not occur when CPS is used as intermediate representation).
-
- 函式皆不返回。
No procedure is allowed to return to its caller–ever.
- 函式結尾處可透過額外傳入的 (回調) 參數動作。
Procedures can take a callback to invoke upon their return value.
-
- CPS 轉換是將控制流轉換成 CPS 型式 (return 語句亦是控制流的一種)。
- Tail call
int foo(int a) { return bar(a); }
Tail calls can be implemented without adding a new stack frame to the call stack. Most of the frame of the current procedure is not needed any more, and it can be replaced by the frame of the tail call, modified as appropriate (similar to overlay for processes, but for function calls).
- 針對 tail call,可以不增長棧,改為修改當前棧,以反映 tail call 調用。
- 將 CPS 結合 TCO 可以免除棧的使用。
-
- Call-with-current-continuation 即是操作 continuation 的運算子。C 語言中的 setjmp/longjmp 提供近似於 call-with-current-continuation 的功能。