Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, you can, on Scala 2.8. Note that, for this to work, you have to include the scala-compiler.jar in your classpath. If you invoke your scala program with <code>scala</code>, it will be done automatically (or so it seems in the tests I made).</p> <p>You can then use it like this:</p> <pre><code>import scala.tools.nsc.Interpreter._ object TestDebugger { def main(args: Array[String]) { 0 to 10 foreach { i =&gt; breakIf(i == 5, DebugParam("i", i)) println(i) } } } </code></pre> <p>You may pass multiple <code>DebugParam</code> arguments. When the REPL comes up, the value on the right will be bound to a val whose name you provided on the left. For instance, if I change that line like this:</p> <pre><code> breakIf(i == 5, DebugParam("j", i)) </code></pre> <p>Then the execution will happen like this:</p> <pre><code>C:\Users\Daniel\Documents\Scala\Programas&gt;scala TestDebugger 0 1 2 3 4 j: Int scala&gt; j res0: Int = 5 </code></pre> <p>You continue the execution by typing <code>:quit</code>.</p> <p>You may also unconditionally drop into REPL by invoking <code>break</code>, which receives a <code>List</code> of <code>DebugParam</code> instead of a vararg. Here's a full example, code and execution:</p> <pre><code>import scala.tools.nsc.Interpreter._ object TestDebugger { def main(args: Array[String]) { 0 to 10 foreach { i =&gt; breakIf(i == 5, DebugParam("j", i)) println(i) if (i == 7) break(Nil) } } } </code></pre> <p>And then:</p> <pre><code>C:\Users\Daniel\Documents\Scala\Programas&gt;scalac TestDebugger.scala C:\Users\Daniel\Documents\Scala\Programas&gt;scala TestDebugger 0 1 2 3 4 j: Int scala&gt; j res0: Int = 5 scala&gt; :quit 5 6 7 scala&gt; j &lt;console&gt;:5: error: not found: value j j ^ scala&gt; :quit 8 9 10 C:\Users\Daniel\Documents\Scala\Programas&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload