0

現在、関数型言語で継続を実験しているとき、継続は現在のプログラムカウンターとレジスタファイルを記録し、継続が返されると、PCと登録ファイルは記録された値に復元されると理解しています。 。

したがって、Mightのブログ投稿からの次のばかげた例では、

; right-now : -> moment
(define (right-now)
  (call-with-current-continuation 
   (lambda (cc) 
     (cc cc))))

; go-when : moment -> ...
(define (go-when then)
  (then then))  


; An infinite loop:
(let ((the-beginning (right-now)))
  (display "Hello, world!")
  (newline)
  (go-when the-beginning))  ; here the-beginning continuation passed to go-when, which ultimately will have an continuation applied to an continuation, that returns a continuation, which will cause the the program point resumed to the PC and registers states recorded in it.

理解が正しいかわかりません。そうでないと思われる場合は訂正してください。

4

1 に答える 1

8

プログラムカウンターとレジスタファイルは、継続が記録するものではありません。

call-with-current-continuationの意味を説明する最良の方法は、プログラムコンテキストを記録することです。たとえば、プログラムを評価しているとします。

(+ 3 (f (call-with-current-continuation g)))

この場合、call-with-current-continuation式のコンテキストは次のようになります。

(+ 3 (f [hole]))

つまり、現在の表現を取り巻くものです。

Call-with-current-continuationは、これらのコンテキストの1つをキャプチャします。継続を呼び出すと、現在のコンテキストが継続に保存されているコンテキストに置き換えられます。

コンテキストの概念はスタックの概念とよく似ていますが、コンテキストでの関数呼び出しについて特別なことは何もありません。

これは非常に簡単な治療法です。このトピックのより詳細で注意深い考察については、Shriram Krishnamurthiの(無料のオンライン)本PLAI、特にパートVIIを参照することを強くお勧めします。

于 2011-03-28T19:56:00.560 に答える