目前,当我在函数式语言中尝试延续时,我的理解是延续记录了当前的程序计数器和寄存器文件,当连续返回时,PC和注册的文件将恢复到它记录的值。
因此,在下面这个来自Might's blog post的愚蠢示例中,
; 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.我不确定我的理解是否正确。如果你认为不是……,请纠正我……
发布于 2011-03-29 03:56:01
程序计数器和寄存器文件不是继续记录的内容。
描述call-with-current- context含义的最好方法是它记录程序上下文。例如,假设您正在评估程序
(+ 3 (f (call-with-current-continuation g)))在本例中,call-with-current- context表达式的上下文为
(+ 3 (f [hole]))也就是说,当前表达式周围的内容。
Call-with-current-continuation捕获了其中一个上下文。调用延续会导致当前上下文被存储在延续中的上下文替换。
上下文的概念与堆栈非常相似,只是上下文中的函数调用没有什么特别之处。
这是一个非常简短的治疗。我强烈建议你看看Shriram Krishnamurthi的(免费的,在线的)书PLAI,特别是第七部分,关于这个主题的更详细和仔细的研究。
https://stackoverflow.com/questions/5463930
复制相似问题