继续记录PC和寄存器状态吗?
目前,当我在函数式语言中试验延续时,我的理解是延续记录了当前的程序计数器和寄存器文件,当延续返回时,PC和注册的文件将恢复为其记录的值。
因此,在以下来自 的愚蠢示例中可能的博文,
; 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.
我不确定我的理解是否正确。如果您认为不对,请纠正我......
currently, when I am experimenting the continuation in functional languages, my understanding is that a continuation records the current program counter and register files, and when a continuation is returned, then the PC and the registered files will be restored to the values it has recorded.
So in the following dumb example from 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.
I am not sure my understanding right.. Please correct me if you think it is not.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
程序计数器和寄存器文件不是延续记录的。
描述 call-with-current-continuation 含义的最好方式是它记录了程序上下文。例如,假设您正在评估程序
,在这种情况下,call-with-current-continuation 表达式的上下文将是
,即当前表达式周围的内容。
Call-with-current-continuation 捕获这些上下文之一。调用延续会导致当前上下文替换为延续中存储的上下文。
上下文的概念很像堆栈,只是上下文中的函数调用没有什么特别之处。
这是一个非常简短的治疗。我强烈建议您看一下 Shriram Krishnamurthi 的(免费在线)书PLAI,特别是第七部分,更详细、更仔细地了解这个主题。
Program counter and register files are not what the continuation records.
The best way to describe the meaning of call-with-current-continuation is that it records the program context. For instance, suppose you're evaluating the program
In this case, the context of the call-with-current-continuation expression would be
That is, the stuff surrounding the current expression.
Call-with-current-continuation captures one of these contexts. Invoking a continuation causes the replacement of the current context with the one stored in the continuation.
The idea of a context is a lot like that of a stack, except that there's nothing special about function calls in contexts.
This is a very brief treatment. I strongly urge you to take a look at Shriram Krishnamurthi's (free, online) book PLAI, in particular Part VII, for a more detailed and careful look at this topic.