首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >continuation是否记录PC和寄存器状态?

continuation是否记录PC和寄存器状态?
EN

Stack Overflow用户
提问于 2011-03-29 03:20:58
回答 1查看 199关注 0票数 0

目前,当我在函数式语言中尝试延续时,我的理解是延续记录了当前的程序计数器和寄存器文件,当连续返回时,PC和注册的文件将恢复到它记录的值。

因此,在下面这个来自Might's blog post的愚蠢示例中,

代码语言:javascript
复制
; 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.

我不确定我的理解是否正确。如果你认为不是……,请纠正我……

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-29 03:56:01

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

描述call-with-current- context含义的最好方法是它记录程序上下文。例如,假设您正在评估程序

代码语言:javascript
复制
(+ 3 (f (call-with-current-continuation g)))

在本例中,call-with-current- context表达式的上下文为

代码语言:javascript
复制
(+ 3 (f [hole]))

也就是说,当前表达式周围的内容。

Call-with-current-continuation捕获了其中一个上下文。调用延续会导致当前上下文被存储在延续中的上下文替换。

上下文的概念与堆栈非常相似,只是上下文中的函数调用没有什么特别之处。

这是一个非常简短的治疗。我强烈建议你看看Shriram Krishnamurthi的(免费的,在线的)书PLAI,特别是第七部分,关于这个主题的更详细和仔细的研究。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5463930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档