25

Question says it all.

(Yet, the details of how to get access to the shift and reset operations has changed over the years. Old blog entries and Stack Overflow answers may have out of date information.)

See also What are Scala continuations and why use them? which talks about what you might want to do with shift and reset once you have them.

2 Answers 2

30

Scala 2.12 or 2.11

The easiest way is to use sbt. Here's what to put in your build.sbt:

scalaVersion := "2.12.2"    
addCompilerPlugin(
  "org.scala-lang.plugins" % "scala-continuations-plugin" % "1.0.3"
    cross CrossVersion.patch)
libraryDependencies +=
  "org.scala-lang.plugins" %% "scala-continuations-library" % "1.0.3"
scalacOptions += "-P:continuations:enable"

In your code (or the REPL), do import scala.util.continuations._

You can now use shift and reset to your heart's content.

Note that I used a Scala version of 2.12.2 because that's the last version the plugin was published for. If you want to use a newer 2.12.x version, you'd need to build the plugin yourself from source. If you use 2.12.2, you'll probably need to be on Java 8, since according to https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html Java 11 support didn't land until 2.12.4.

historical information for Scala 2.8, 2.9, 2.10

You have to start scala (or scalac) with the -P:continuations:enable flag.

In your code, do import scala.util.continuations._

You can now use shift and reset to your heart's content.

If you're using sbt 0.7, see https://groups.google.com/forum/#!topic/simple-build-tool/Uj-7zl9n3f4

If you're using sbt 0.11+, see https://gist.github.com/1302944

If you're using maven, see http://scala-programming-language.1934581.n4.nabble.com/scala-using-continuations-plugin-with-2-8-0-RC1-and-maven-td2065949.html#a2065949

Sign up to request clarification or add additional context in comments.

5 Comments

Note that if you are using the eclipse plugin, put "continuations:enable" in the "P" compiler preferences, and also be sure to clear out the "Xpluginsdir" pref, as the default values in there seem to interfere with using the continuations plugin.
Thank you Mitch Blevins -- I was having trouble until I cleared out the Xpluginsdir pref. Could not find that advice anywhere else.
Thanks Mitch, I also had to clear the Xpluginsdir field. Furthermore it didn't work until I did a clean.
Anyone please tell me how to use with gradle?
7

Non SBT solution:

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

Works on scala 2.11.6, but the plugin/library said that it will no longer be included with Scala 2.12

1 Comment

Note that perhaps someone will update the plugin to work with 2.12, even though it will definitely no longer be bundled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.