35

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?

Community
  • 1
  • 1
DaoWen
  • 32,589
  • 6
  • 74
  • 101
  • Why not just put a breakpoint in Eclipse and have it stop there, as you can give it conditions. – James Black Oct 21 '12 at 16:40
  • @James Black - Yes, if I'm using Eclipse that's an option. However, I really doubt that's why this functionality was removed from the 2.10 codebase. – DaoWen Oct 21 '12 at 17:10
  • You could look in the repository perhaps, as when it was removed, and see if they put in a reason. – James Black Oct 23 '12 at 16:05
  • 1
    @James Black - There's a link to the commit in the post linked to above. It was removed as part of a large commit (affecting a lot of files) with the commit message "Removing more unneeded code." – DaoWen Oct 23 '12 at 17:46

1 Answers1

6

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.

Steve
  • 3,038
  • 2
  • 27
  • 46
  • 1
    So the answer is that they want us to re-implement it ourselves? – DaoWen Nov 07 '12 at 01:09
  • Well, I can't speak for the Scala developers. But one answer could be that it wasn't flexible enough to be used as-is (e.g. if you needed `-Yrepl-sync`), and making it more flexible would have made it as complicated just writing the code itself. – Steve Nov 07 '12 at 09:56
  • 1
    That said, some better default for `ILoop.settings` and `ILoop.in` would make the above code much more palatable. I'm not at all bothered by the `createInterpreter`, `bind`, `loop` or `closeInterpreter` calls, since these are exactly what we're trying to accomplish here. But having to set `var`s on the ILoop feels wrong. – Steve Nov 07 '12 at 09:58
  • 1
    Initially, when I tried the above code in 2.10.2 the interpreter hung. What got it working for me was adding `repl.settings.Yreplsync.value = true` – Ben Hutchison Sep 05 '13 at 04:40