问题说明了一切。如何在Scala中启用延续?
(然而,如何获得访问shift
和reset
操作细节已经改变了多年来,老的博客文章和堆栈溢出的答案可能有过时的信息。)
参见What are Scala continuations and why use them?其中谈到关于一旦你拥有它们,你可能想要用shift
和reset
做什么。
问题说明了一切。如何在Scala中启用延续?
(然而,如何获得访问shift
和reset
操作细节已经改变了多年来,老的博客文章和堆栈溢出的答案可能有过时的信息。)
参见What are Scala continuations and why use them?其中谈到关于一旦你拥有它们,你可能想要用shift
和reset
做什么。
斯卡拉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
到你心中的内容。
斯卡拉2.8,2.9的历史信息,2.10
你必须开始与-P:continuations:enable
标志斯卡拉(或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
非SBT的解决方案:
scala -Xpluginsdir /.../scala/lib/ -P:continuations:enable
作品上阶2.11.6,但该插件/库said,它将不再includ用Scala编辑2.12
请注意,也许有人会更新插件与2.12一起工作,即使它肯定不会被捆绑。 – 2015-09-19 00:30:11
请注意,如果您使用的是eclipse插件,请在“P”编译器偏好设置中放置“continuations:enable”,并且一定要清除“Xpluginsdir”pref,作为其中的默认值似乎会干扰使用continuations插件。为Eclipse用户提供的 – 2010-04-21 15:52:15
,请参阅http://stackoverflow.com/questions/4556540/continuations-in-scala-2-8-1-and-eclipse – 2011-01-04 17:34:29
谢谢米奇Blevins - 我有麻烦,直到我清除了Xpluginsdir优先。无法在其他地方找到该建议。 – Eric 2011-06-04 02:36:28