- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Scala 2.9.0 final
Created by admin on 2011-05-12.
Updated: 2011-08-31, 10:17
We are happy to announce the release of the new stable release of the Scala distribution. The new Scala 2.9.0 final 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.
Scala 2.9.0 is also available in a simple, pre-integrated stack with Akka 1.1 from Typesafe at http://typesafe.com/stack
The Scala 2.9.0 distribution
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.
Please note: an incorrect version of the binaries appeared for a brief time on the Maven repositories only. If you fetched 2.9.0 final from Maven prior to this announcement, you may have to clean your local cache in order to fetch the correct version.
- Login or register to post comments
- Printer-friendly version
Re: Scala 2.9.0 final
Hi, I'm newbie to scala, and I tried code
saved it as echo.scala and executed it ofcourse with parameters and no output.Then tried it worked... so is there something wrong? Thank youRe: Scala 2.9.0 final
It's an issue with the way you are running the program. Try to compile the code first with :
Then you can run it with :
Re: Scala 2.9.0 final
Thanks.. :) Now works...
Re: Scala 2.9.0 final
I use the scala 2.9.0 final in ubuntu 11.04:
Hello.scala
object Hello {
def main(args: Array[String]){
var i = 0;
while( i < args.length ){
println("Hello " + args(i) );
i += 1;
}
}
}
scalac Hello.scala,it can works。
but when I scala Hello,throw some exception like this :
Exception in thread "main" java.lang.RuntimeException: Cannot figure out how to run target: Hello
at scala.sys.package$.error(package.scala:27)
at scala.tools.nsc.GenericRunnerCommand.scala$tools$nsc$GenericRunnerCommand$$guessHowToRun(GenericRunnerCommand.scala:38)
at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
at scala.Option.getOrElse(Option.scala:109)
at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:48)
at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:17)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:33)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
How can I fixed that exception
Re: Scala 2.9.0 final
bulat@nigmatullin:~$ cat Echo.scala
object Echo extends App {
println("Echo" + (args mkString " "))
}
Echo.main(args);
bulat@nigmatullin:~$ scala Echo.scala
Echo
bulat@nigmatullin:~$ scala Echo.scala 123
Echo123
bulat@nigmatullin:~$
Re: Scala 2.9.0 final
I am very sorry!
because I set the CLASSPATH=$JAVA_HOME/lib
when I set the CLASSPATH=$JAVA_HOME/lib:.,I fix the problem.
if the CLASSPATH doesn't point to the current path,it can't find the Hello.class in the CLASSPATH
thanks for you answer my question!
Re: Scala 2.9.0 final
I'm sorry. I thought you are trying to run Scala script.
I don't know your environment features, but by default, no configuration is required to run examples. Just put Scala bin directory in your PATH variable and enjoy.
bulat@nigmatullin:~$ cat Hello.scala
object Hello {
def main(args: Array[String]){
var i = 0;
while( i < args.length ){
println("Hello " + args(i) );
i += 1;
}
}
}
bulat@nigmatullin:~$ scalac Hello.scala
bulat@nigmatullin:~$ scala Hello 1
Hello 1
bulat@nigmatullin:~$ echo $PATH
/opt/sbt:/opt/scala/bin:/opt/apache-maven-3.0.3/bin:/opt/apache-ant-1.8.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
bulat@nigmatullin:~$ echo $CLASSPATH
bulat@nigmatullin:~$ echo $JAVA_HOME
bulat@nigmatullin:~$
Re: Scala 2.9.0 final
Thank you for your great job and new Scala release.
Re: Scala 2.9.0 final
execited -> executed I believe