【问题标题】:How do I enable continuations in Scala?如何在 Scala 中启用延续?
【发布时间】:2011-02-10 14:38:22
【问题描述】:

问题说明了一切。

(然而,多年来,如何访问 shiftreset 操作的详细信息发生了变化。旧博客条目和 Stack Overflow 答案可能包含过时的信息。)

另请参阅What are Scala continuations and why use them?,其中讨论了您在拥有shiftreset 后可能想要做什么。

【问题讨论】:

    标签: scala continuations


    【解决方案1】:

    Scala 2.11

    最简单的方法是使用sbt:

    scalaVersion := "2.11.6"
    
    autoCompilerPlugins := true
    
    addCompilerPlugin(
      "org.scala-lang.plugins" % "scala-continuations-plugin_2.11.6" % "1.0.2")
    
    libraryDependencies +=
      "org.scala-lang.plugins" %% "scala-continuations-library" % "1.0.2"
    
    scalacOptions += "-P:continuations:enable"
    

    在您的代码(或 REPL)中,执行 import scala.util.continuations._

    您现在可以尽情使用shiftreset

    Scala 2.8、2.9、2.10 的历史信息

    您必须使用 -P:continuations:enable 标志启动 scala(或 scalac)。

    在您的代码中,执行import scala.util.continuations._

    您现在可以尽情使用shiftreset

    如果您使用的是 sbt 0.7,请参阅 https://groups.google.com/forum/#!topic/simple-build-tool/Uj-7zl9n3f4

    如果您使用的是 sbt 0.11+,请参阅 https://gist.github.com/1302944

    如果您使用的是 maven,请参阅 http://scala-programming-language.1934581.n4.nabble.com/scala-using-continuations-plugin-with-2-8-0-RC1-and-maven-td2065949.html#a2065949

    【讨论】:

    • 请注意,如果您使用的是 eclipse 插件,请将“continuations:enable”放在“P”编译器首选项中,并确保清除“Xpluginsdir”首选项,作为默认值似乎有干扰使用延续插件。
    • 对于 Eclipse 用户,请参阅 stackoverflow.com/questions/4556540/…
    • 谢谢 Mitch Blevins -- 在我清除 Xpluginsdir 首选项之前我遇到了麻烦。在其他任何地方都找不到该建议。
    • 谢谢 Mitch,我还必须清除 Xpluginsdir 字段。此外,直到我清理干净后它才起作用。
    • 谁能告诉我如何使用gradle?
    【解决方案2】:

    非 SBT 解决方案:

    scala -Xpluginsdir /.../scala/lib/ -P:continuations:enable
    

    适用于 Scala 2.11.6,但插件/库 said 将不再包含在 Scala 2.12 中

    【讨论】:

    • 请注意,也许有人会更新插件以使用 2.12,即使它肯定不再捆绑。
    猜你喜欢
    • 2014-11-13
    • 1970-01-01
    • 2020-04-06
    • 2011-06-01
    • 2013-07-01
    • 1970-01-01
    • 2015-05-26
    • 2012-03-29
    • 2011-10-14
    相关资源
    最近更新 更多