如何在Scala中启用延续?

Set*_*sue 24 continuations scala

问题说明了一切.

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

另请参阅什么是Scala延续以及使用它们的原因?其中谈到你可能想用做什么shiftreset一旦你有他们.

Set*_*sue 29

斯卡拉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"
Run Code Online (Sandbox Code Playgroud)

在你的代码(或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插件,请在"P"编译器首选项中输入"continuations:enable",并确保清除"Xpluginsdir"pref,因为其中的默认值似乎会干扰使用continuation插入. (4认同)

krr*_*rrr 7

非SBT解决方案:

scala -Xpluginsdir /.../scala/lib/ -P:continuations:enable
Run Code Online (Sandbox Code Playgroud)

适用于scala 2.11.6,但插件/库表示它将不再包含在Scala 2.12中