6

Scala newbie here, I just downloaded Eclipse 3.6.2 and Scala IDE 2.0.0-beta4 (with Scala 2.9.0.final). I create a new Scala project to try delimited continuations:

package delimCCTests

import scala.util.continuations._

object Test extends App {
  val result = reset {
    1 + shift { k: (Int => Int) => k(k(5)) } + 1
  }
  println(result)
}

This compiles fine, then I click Run as -> Scala application and get this exception:

Exception in thread "main" java.lang.NoSuchMethodError: scala.util.continuations.package$.shift(Lscala/Function1;)Ljava/lang/Object;
    at delimCCTests.Test$$anonfun$1.apply$mcI$sp(DelimCCTests.scala:7)
    at delimCCTests.Test$$anonfun$1.apply(DelimCCTests.scala:7)
    at delimCCTests.Test$$anonfun$1.apply(DelimCCTests.scala:7)
    at scala.util.continuations.package$.reset(package.scala:20)
    at delimCCTests.Test$delayedInit$body.apply(DelimCCTests.scala:6)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:60)
    at scala.App$$anonfun$main$1.apply(App.scala:60)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
    at scala.App$class.main(App.scala:60)
    at delimCCTests.Test$.main(DelimCCTests.scala:5)
    at delimCCTests.Test.main(DelimCCTests.scala)

What am I doing wrong? Am I missing some configuration?

BTW I thought the compiler inferred the type of the continuation? This article uses:

val result = reset {
   1 + shift { k => k(k(5)) } + 1                   
}

but this doesn't compile in my environment...

Vasil Remeniuk
  • 20,519
  • 6
  • 71
  • 81
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • So what changes between the compile environment and the run-time environment? :-) My first suspect is a conflicting (unexpected and different) Scala run-time library being used. –  May 19 '11 at 22:41
  • @pst: it certainly looks like that, but I've never had Scala in this box before, so it can't be a version mismatch, right? – Mauricio Scheffer May 19 '11 at 22:48
  • Tried this code on the REPL with identical result (Scala version 2.9.0.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_25) on Windows 7 64-bit) – Mauricio Scheffer May 20 '11 at 03:10
  • Ultimately, I couldn't make this work with Eclipse, but IDEA worked flawlessly. – Mauricio Scheffer May 20 '11 at 20:56

2 Answers2

3

This error means that you didn't add Scala CPS plugin - it's not a part of a standard assembly (so far). Put the jar on the classpath, and run Scala is follows, in order to have continuations enabled:

$ scala -P:continuations:enable
Vasil Remeniuk
  • 20,519
  • 6
  • 71
  • 81
  • Nope, I did as explained in http://stackoverflow.com/questions/4556540/continuations-in-scala-2-8-1-and-eclipse/4557174#comment-7005822 and I get a compile-time error: "bad option: -P:continuations:enable" – Mauricio Scheffer May 20 '11 at 12:58
  • Also, how come it finds `reset` but not `shift` ? – Mauricio Scheffer May 20 '11 at 12:59
  • 1
    "bad option: -P:continuations:enable" - this error means that you don't have `continuations.jar` on the classpath – Vasil Remeniuk May 20 '11 at 13:30
  • "Also, how come it finds reset but not shift" ~> because interface methods of the continuations are a part of a standard compiler distribution (and only implementation, the plugin itself, that makes the transformation, goes separately) – Vasil Remeniuk May 20 '11 at 13:34
  • @Vasil: thanks, I added continuations.jar to the classpath and now continuations:enable works fine. But I'm still getting that error at runtime... and yes, I made sure my code was rebuilt :) – Mauricio Scheffer May 20 '11 at 15:13
  • Okay, which version of `continuations.jar` are you using? Can you run the code straight against `scala` (not from eclipse) making sure that both compiler and continuations plugin have the same version of `2.9.0` – Vasil Remeniuk May 20 '11 at 15:23
  • I must be missing some stupid little detail as a result of my newbieness! – Mauricio Scheffer May 20 '11 at 15:24
  • It's the only continuations.jar I have. It's in c:\Program Files\eclipse\configuration\org.eclipse.osgi\bundles\291\1\.cp\lib\ , the same directory where `scala-compiler.jar` is. – Mauricio Scheffer May 20 '11 at 15:26
  • Try out with the version `2.9.0` ~> http://mvnrepository.com/artifact/org.scala-lang.plugins/continuations/2.9.0 – Vasil Remeniuk May 20 '11 at 15:28
  • I can use continuations running `scala` or `scalac` from the shell but can't get it to work with eclipse? Anyone here know a solution or should I open a new question? – Ell Jul 10 '14 at 16:40
1

This can be solved in eclipse by adding the CPS plugins class on the Scala Compiler > Advanced section, as well as enabling the switch:

Enabling the continuations switch Adding the plugin and setting the plugins path Xplugin should be scala.tools.selectivecps.SelectiveCPSPlugin and Xpluginsdir should be the dir which contains org.scala-lang.plugins.scala-continuations-plugin.jar

Ell
  • 4,238
  • 6
  • 34
  • 60