分隔延续和不分隔延续之间的区别

发布于 2024-11-08 14:00:14 字数 256 浏览 5 评论 0原文

我想delimitedundelimited延续之间的区别就像calljump之间的区别。

如果我们调用delimited延续,它将在完成后返回给调用者。如果我们调用 undelimited 延续,它的工作方式就像 goto 并且永远不会返回给调用者。

有道理吗?我错过了什么吗?

I guess the difference between delimited and undelimited continuations is like the difference between call and jump.

If we invoke delimited continuation it will return to the caller once it finishes. If we invoke undelimited continuation it works like goto and never returns to the caller.

Does it make sense? Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

讽刺将军 2024-11-15 14:00:14

你有点偏离轨道了。无论哪种风格的延续,都与 goto(跳转)没有太大关系。然而,它们与堆栈有关。


经典延续

请记住,常规延续将控制堆栈的概念捕获为第一类值。堆栈可以被命名,作为参数传递,并且可以将值应用于它们,从而使用基于通过 callCC 的函数应用的简单 API 来改变控制流。

分隔延续

分隔延续会添加到组合中吗?

回想一下,常规延续捕获直到某个点的整个调用堆栈。如果我们可以在其中放置标记来准确说明在延续中要捕获多少控制堆栈呢?控制堆栈的一种“定界”。

这就是想法,现在您拥有超酷的定界延续:将程序的任意部分作为值进行定界、捕获和操作。非常适合恢复和增量处理以及其他棘手形式的控制流。

参考文献

注释

Oleg Kiselyov 的一些更正,已收到列表外:

You're a bit off track. Continuations, of either flavor, have nothing much to do with goto (jumps). They have everything to do with the stack, however.


Classic Continuations

Remember regular continuations capture the notion of a control stack as a first class values. Stacks may be named, passed around as arguments, and values may be applied to them, yielding a change in control flow, with a simple API based on function application via callCC.

Delimited Continuations

What do delimited continuations add to the mix?

Recall that regular continuations capture the entire call stack up to a certain point. What if we could put markers in that say exactly how much of the control stack to capture in the continuation? A sort of "delimit"ing of the control stack.

That's the idea, and now you have super-cool delimited continuations: delimit, capture and manipulate arbitrary portions of a program, as a value. Perfect for resumption and incremental processing, and other tricky forms of control flow.

References

Notes

Some corrections from Oleg Kiselyov, received off-list:

思念绕指尖 2024-11-15 14:00:14

作为语言功能的延续(与作为编程模式的延续相反)是控制上下文(“堆栈”)(的一部分)的具体化。正如 Don 所说,无界延续代表整个上下文,而定界延续仅代表其中的一部分。

通常,捕获无限制的延续(例如,使用call/cc)不会更改控制上下文;仅当调用延续时(即反映到堆栈上),控制上下文才会更改。

通常,捕获定界延续(例如,使用 shift)会立即中止控制上下文的片段,直到最近的定界符(例如,reset),并将其具体化为看起来的样子成为一个普通的旧函数(尽管它可能以堆栈欺骗的形式实现,而不是实现正常的函数)。

顺便说一句,延续有时被称为“一流跳转”,但这并不意味着它们与 jmp 指令的关系比普通函数调用更多。

Continuations as a language feature (as opposed to continuations as a programming pattern) are reifications of (parts of) the control context ("the stack"). As Don said, undelimited continuations represent the whole context, whereas delimited continuations only represent part of it.

Typically, capturing an undelimited continuation (eg, with call/cc) doesn't change the control context; the control context is only changed when the continuation is invoked (ie, reflected onto the stack).

Typically, capturing a delimited continuation (eg, with shift) immediately aborts the segment of the control context up to the nearest delimiter (eg, reset) and reifies that as what seems to be a plain old function (although it might be implemented as stack trickery rather than however normal functions are implemented).

BTW, continuations are sometimes called "first-class jumps", but that doesn't mean they have any more to do with the jmp instruction than a normal function call does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文