This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Scala 2.9.0 RC4

After some additional polishing, a new release candidate is ready: we are now getting really close to the final release! Scala 2.9.0 RC4 is available from our Download Page. The Scala 2.9.0 codebase includes several additions, notably the new Parallel Collections, but it also introduces improvements on many existing features, and contains many bug fixes.

Please help us with the testing of this release candidate, and let us know of any issues you may detect.

 

The Scala 2.9.0 distribution

This Release Candidate is made available for testing purposes only and is not intended for production environments. We invite all developers and testers to send us their feedback at this time.

What is new?

The new Scala 2.9 codebase includes the following new features and changes: 

Parallel Collections

Every collection may be converted into a corresponding parallel collection with the new `par` method. Parallel collections utilize multicore processors by implementing bulk operations such as `foreach`, `map`, `filter` etc. in parallel. Parallel collections are located in the package `scala.collection.parallel`.

Depending on the collection in question, `par` may require copying the underlying dataset to create a parallel collection. However, specific collections share their underlying dataset with a parallel collection, making `par` a constant time operation.

Currently available parallel collections are:

  • parallel arrays - scala.collection.parallel.mutable.ParArray
  • parallel ranges - scala.collection.parallel.immutable.ParRange
  • parallel hash maps - scala.collection.parallel.mutable.ParHashMap
  • parallel hash sets - scala.collection.parallel.mutable.ParHashSet
  • parallel hash tries - scala.collection.parallel.immutable.{ParHashMap, ParHashSet}
  • parallel vectors - scala.collection.parallel.immutable.ParVector

The method `seq` is used to convert from a parallel collection to a corresponding sequential collection. This method is always efficient (O(1)).

 

The App Trait

The App trait is a safer, more powerful alternative to the previous Application trait, which has now been deprecated. The new recommended way to write a top-level application is like this:

object Echo extends App {
  println("Echo" + (args mkString " "))
}

Objects inheriting from the old Application trait were almost as convenient to write,  but were not thread-safe and were often not optimized by the VM, since the application’s body was execited as part of of the object’s initialization sequence. Objects inheriting the App trait instead make use of Scala 2.9’s delayed initialization feature to execute the whole body as part of an inherited main method.

Another new feature of the App scheme is that command line arguments are now accessible via the args value (which is inherited from trait App)

The DelayedInit Trait

The DelayedInit trait provides another tool to customize initialization sequences of classes and objects. If a class or object inherits from this trait, all its initialization code is packed in a closure and forwarded as an argument to a method named delayedInit which is defined as an abstract method in trait DelayedInit.

Implementations of delayedInit have thus full freedom when to execute the initialization code. For instance, Scala’s new App trait stores all initialization sequences in an internal buffer and executes them when the object’s main method is called.

Note that only initialization code contained in classes and objects is passed to DelayedInit; initialization code contained in traits is not affected.

Repl Improvements

Improvements in jline, the repl input handler.  More robust cursor handling, bash-style ctrl-R history search, new commands like :imports, :implicits, :keybindings.  On platforms with the necessary runtime support, :javap will disassemble any class including repl-defined ones.  A long-running repl command can now be interrupted via ctrl-C without terminating the repl session.  Improved programmability: the repl classloader exposes repl-defined classes via their given names.

Scala Runner

Scala code can now be executed in any of the following ways:

  • scala <jarfile> will run the main class, similar to java -jar
  • scala <classname> will run the main method of that class
  • scala <sourcefile> will run the script contents as a scala script
  • scala <sourcefile> will, if the contents are not a script, find a single main method in a top level object and run that.  This allows the same file to be used with scalac and to be run directly.
  • scala -save <sourcefile> will create a jar file with the compiled source, which is then reusable and can be run as scala <jarfile>

Java Interop

The @strictfp annotation is now supported.

Various fixes in JavaConverters and JavaConversions for smoother interoperation.

Primitive types and their boxed versions are now implicitly converted bidirectionally.

 

Other features

  • Generalized try-catch-finally:
try body
catch handler
finally cleanup

Here, body and cleanup can be arbitrary expressions, and handler can be any expression which evaluates to a valid exception handler (which is: PartialFunction[Throwable, T]).

  • New packages:
    scala.sys and scala.sys.process, which are imported from sbt.Process.
  • New methods in collections:
    collectFirst, maxBy, minBy, span, inits, tails, permutations, combinations, subsets
     
  • AnyRef specialization:
    It’s now possible to specialize on type parameters for subtypes of AnyRef (class Foo[@specialize(AnyRef) T](arr: Array[T]) { … }), which allows for more efficient array indexing and updates.

And a large number of bugfixes and performance improvements.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland