替代Scala REPL breakIf在2.10中

我在这里阅读了关于在REPL代码中使用breakIf方法进行交互式debugging的问题,但是后来我发现这个post中说breakbreakIf是从Scala 2.10中的breakIf中删除的。 不幸的是,这个post并没有解释为什么代码被删除。

我假设这些function被删除,因为有更好的方法来做到这一点。 如果是这样的话,有人可以赐教吗?

也许这个想法是你应该直接使用ILoop ? 据我所知,它不应该比以下更复杂:

 // insert the code below wherever you want a REPL val repl = new ILoop repl.settings = new Settings repl.in = SimpleReader() repl.createInterpreter() // bind any local variables that you want to have access to repl.intp.bind("i", "Int", i) repl.intp.bind("e", "Exception", e) // start the interpreter and then close it after you :quit repl.loop() repl.closeInterpreter() 

与旧的breakIf API相比,这种方法为if条件(被包装成一个=> Boolean )和DebugParam / NamedParam (临时包装器只用来填充bind参数)摆脱了额外的间接级别)。

这种方法还允许您根据需要指定您的Settings 。 例如, 一些REPL错误可以通过-Yrepl-sync解决,但是break让你无法指定 。