25

问题说明了一切。

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

另请参阅什么是 Scala 延续以及为什么使用它们?它谈到了你可能想要做的事情shift以及reset一旦你拥有它们。

4

2 回答 2

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"

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

您现在可以随心所欲地shift使用reset

Scala 2.8、2.9、2.10 的历史信息

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

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

您现在可以随心所欲地shift使用reset

如果您使用的是 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

于 2010-04-21T13:21:16.723 回答
7

非 SBT 解决方案:

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

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

于 2015-06-06T14:45:50.397 回答