問題說明了一切。如何在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