是否继续记录PC并注册状态?

0 scheme continuations functional-programming racket

目前,当我正在尝试功能语言的延续时,我的理解是继续记录当前程序计数器和寄存器文件,当返回延续时,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.
Run Code Online (Sandbox Code Playgroud)

我不确定我的理解是对的..如果你认为不是,请纠正我.....

Joh*_*nts 8

程序计数器和寄存器文件不是延续记录的内容.

描述call-with-current-continuation意义的最好方法是记录程序上下文.例如,假设您正在评估该计划

(+ 3 (f (call-with-current-continuation g)))
Run Code Online (Sandbox Code Playgroud)

在这种情况下,call-with-current-continuation表达式的上下文将是

(+ 3 (f [hole]))
Run Code Online (Sandbox Code Playgroud)

也就是说,围绕当前表达的东西.

Call-with-current-continuation捕获其中一个上下文.调用continuation会导致使用存储在continuation中的那个替换当前上下文.

上下文的概念很像堆栈的概念,除了上下文中的函数调用没有什么特别之处.

这是一个非常简短的治疗方法.我强烈建议你看一下Shriram Krishnamurthi(免费在线)书PLAI,特别是第七部分,以便更详细和仔细地看一下这个主题.