Scala 运行时分隔延续错误

发布于 2024-11-08 13:00:59 字数 1856 浏览 3 评论 0原文

Scala 新手,我刚刚下载了 Eclipse 3.6.2 和 Scala IDE 2.0.0-beta4(带有 Scala 2.9.0.最终版)。我创建一个新的 Scala 项目来尝试分隔延续:

package delimCCTests

import scala.util.continuations._

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

这可以正常编译,然后我单击 Run as -> Scala 应用程序并出现此异常:

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)

我做错了什么?我是否缺少某些配置?

顺便说一句,我认为编译器推断了延续的类型? 本文使用:

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

但这并不在我的环境中无法编译...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绮筵 2024-11-15 13:00:59

此错误意味着您没有添加 Scala CPS 插件 - 它不是标准程序集的一部分(到目前为止)。将 jar 放在类路径上,然后运行Scala 如下,以便启用延续:

$ scala -P:continuations:enable

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
合约呢 2024-11-15 13:00:59

这个问题可以在eclipse中通过在Scala Compiler > CPS插件类中添加来解决高级部分,以及启用开关:

启用延续开关
添加插件并设置插件路径
Xplugin 应该是 scala.tools.selectivecps.SelectiveCPSPluginXpluginsdir 应该是包含 org.scala-lang.plugins 的目录。 scala-continuations-plugin.jar

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文