【问题标题】:Can we describe Clojure's core.async as 'continuation passing style'?我们可以将 Clojure 的 core.async 描述为“延续传递风格”吗?
【发布时间】:2013-12-30 21:35:50
【问题描述】:

在 Clojure 的 core.async library 中,我们看到 macro that creates a state machine 环绕 go 块以创建处理阻塞 IO 的通道。

这似乎是modelling on C#'s async and on Go-lang's goroutines

Seasoned Schemer - 他们描述techniques for passing continuations。 (这似乎是based on call/cc)。我们还在 Clojure 中的 delimited continuations 上看到了来自 David Nolen 的库。

Here they describe C#'s async 为“call with current continuation”。

我的问题是我们可以将 Clojure 的 core.async 描述为“continuation passing style”吗?

或者“延续”(delimited and undelimited)是一个重载的术语?


编辑: 另外一点 - David Nolen has said wrt to core.async:

在 go 块中,它给您一种错觉,即您可以以同步的方式执行这些操作,这样您就不必手动编写延续传递样式的代码。

【问题讨论】:

    标签: clojure continuations goroutine callcc core.async


    【解决方案1】:

    我在这里看到两个问题:

    1. 使用 core.async 编程是否类似于继续传递风格的编程?

    2. core.async 的内部是否与 CPS 相关?

    1. 的答案是“否”,因为没有明确的延续。事实上,这就是重点。使用 core.async 的主要原因之一是逃避回调地狱,这基本上是 CPS 坏了(回调是延续)。

    2. 的简单答案也是“否”,因为go 宏使用SSA 内部表示来生成状态机。然而,SSA 和 CPS 确实是相关的,因为它们用于相似的目的(即,作为编译器中的内部表示;它们在表面上感觉不同并且在语义上并不完全等效,但在实现类似核心的东西时.async 原则上你可以使用其中任何一个)。

    【讨论】:

      【解决方案2】:

      某种意义上是CPS,但实现更像是到处goto链接的代码块。

      Tim Baldridge 在这里有两个视频讨论 go 宏的实现。请注意:总共有两个小时,他详细介绍了 state machine 的实现方式和工作原理。

      Core Async Go Macro Internals - Part I

      Core Async Go Macro Internals - Part 2

      还有一个宏的必备视频

      Deep Walking Macros

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-19
        • 2011-06-30
        • 2010-12-21
        • 1970-01-01
        • 2011-02-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多