Alternative to Scala REPL breakIf in 2.10

不羁的心 提交于 2019-12-03 05:33:55

问题


I was reading here about using the breakIf method in the REPL code for interactive debugging, but then I found this post saying that break and breakIf were removed from ILoop in Scala 2.10. Unfortunately, that post doesn't explain why the code was removed.

I'm assuming that these functions were removed because there's a better way of doing this. If that's the case, could someone please enlighten me?


回答1:


Perhaps the idea is that you should just work with the ILoop directly? As far as I can tell, it shouldn't be much more complex than:

// 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()

Compared to the old breakIf API, this approach gets rid of an additional level of indirection for both the if condition (which was wrapped into a => Boolean) and the DebugParam/NamedParam (which were temporary wrappers used only to fill in the bind arguments).

This approach also allows you to specify your Settings as needed. For example, some REPL bugs can be worked around with -Yrepl-sync but break gave you no way of specifying that.



来源:https://stackoverflow.com/questions/12939732/alternative-to-scala-repl-breakif-in-2-10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!