我不知道如何编写可以放入
Scala 2.9代码的解释器的代码.这个问题是后续的
this one,它询问Scala的等价物,
import pdb pdb.set_trace()
来自Python.给出的建议主要是针对Scala 2.8,相关的软件包不再存在于以前的表单中.也就是说,
> scala.nsc.tools.nsc.Interpreter.{break,breakIf}已被移动到scala.nsc.tools.nsc.interpreter.ILoop.{break,breakIf}
> DebugParam现在是scala.tools.nsc.interpreter中的NamedParam
如原始帖子中所述,父进程的类路径不会自动传递给新的解释器,所以解决方法已经被提交here.不幸的是,许多在这里调用的类/方法现在已经改变了,我不是确定如何修改代码行为“预期”.
谢谢!
编辑:这是我的测试代码,在当前的编译和运行,但尝试在调试器中执行任何操作会导致应用程序冻结,如果由scalac编译并由scala执行
import scala.tools.nsc.interpreter.ILoop._ object Main extends App { case class C(a: Int,b: Double,c: String) { def throwAFit(): Unit = { println("But I don't wanna!!!") } } // main override def main(args: Array[String]): Unit = { val c = C(1,2.0,"davis") 0.until(10).foreach { i => println("i = " + i) breakIf(i == 5) } } }
EDIT2:由于我目前的设置是通过sbt运行的,我发现这个主题已经被覆盖在in the FAQ(页面底部).然而,我不明白所给出的解释,对MyType的任何澄清都是无价的.
EDIT3:没有解决方案的话题的另一个讨论:http://permalink.gmane.org/gmane.comp.lang.scala.simple-build-tool/1622
解决方法
所以我知道这是一个老问题,但如果你的REPL挂起来,我想知道问题是
you need to supply the
-Yrepl-sync
option吗?当我的嵌入式REPL挂在类似的情况下,就解决了它.
要在嵌入式REPL中设置-Yrepl-sync,而不是使用breakIf,则需要使用work with the ILoop
directly,以便您可以访问“设置”对象:
// create the ILoop val repl = new ILoop repl.settings = new Settings repl.in = SimpleReader() // set the "-Yrepl-sync" option repl.settings.Yreplsync.value = true // start the interpreter and then close it after you :quit repl.createInterpreter() repl.loop() repl.closeInterpreter()