Created by extempore on 2009-06-05. Updated: 2009-06-06, 09:07

The Scala Interpreter (often called a REPL for Read-Evaluate-Print Loop) sits in an unusual design space - an interactive interpreter for a statically typed language straddles two worlds which historically have been distinct. In version 2.8 the REPL further exploits the unique possibilities.

Package and Class Completion

On startup, the REPL analyzes your classpath and creates a database of every visible package and path. This is available via tab-completion analagous to the path-completion available in most shells. If you type a partial path, tab will complete as far as it can and show you your options if there is more than one.

scala> scala.co<tab> collection compat concurrent scala> org.w3c.dom.DOMI<tab> DOMImplementation DOMImplementationList DOMImplementationSource

scala> org.w3c.dom.DOMImplementation

Member Completion

Both static and instance methods of objects are also available.

scala> val x = "abc" x: java.lang.String = abc scala> x.re<tab> regionMatches replace replaceAll replaceFirst scala> java.lang.String.c<tab> scala> java.lang.String.copyValueOf

And because this is all accomplished on the fly via reflection, even anonymous classes you've only just defined are equally accessible.

scala> val x = new AnyRef { def kltpzyxm = "back to the 5th dimension" }

x: java.lang.Object{def kltpzyxm: java.lang.String} = $anon$1@9cb63b

scala> x.<tab>

asInstanceOf getClass isInstanceOf kltpzyxm toString

Interactive Debugging

The interpreter can now be conditionally launched from at an arbitrary point in a program, and make your program internals available interactively. The arguments passed to Interpreter.breakIf can be inspected with tab-completion and even modified, with program execution resuming once you quit the REPL.

Coming Soon, Scala 2.8

There are many more minor improvements and conveniences in the REPL since the 2.7 release. New features for the REPL are largely driven by user feedback, so take a nightly build for a spin and tell us what you'd like to see.