This page is no longer maintained — Please continue to the home page atwww.scala-lang.org
| Source | Description |
|---|---|
| abstractTypes.scala | An example of how abstract types are used in a program |
| bigint.scala | User-defined integers, BigInts, are used seamlessly |
| complexOps.scala | Operators can be defined on user-defined classes, here complex numbers |
| for-yield.scala | An example of thefor andyield constructs |
| extendBuiltins.scala | Adding "!" as a new method on integers |
| implicits.scala | Define a new method 'sort' on arrays without changing their definition |
| maps.scala | Maps are easy to use in Scala |
| match.scala | Using pattern matching to recognize command line arguments |
| primes.scala | A simple, although inefficient, way to calculate prime numbers |
| sum.scala | Calculates the sum of the arguments supplied on the command line |
| varargs.scala | Java varargs can be easily used in Scala as well |
To compile and run on Windows one of the above Scala programs, let's saysort.scala, we can simply proceed as follows:
> mkdir classes> scalac -d classes %SCALA_HOME%\doc\scala-devel-docs\scala\examples\sort.scala> scala -cp classes examples.sort[6,2,8,5,1][1,2,5,6,8]
The name of the Scala executable isexamples.sort whereexamples is the name of the package containing thesort object. Running the test on a Unix system is very much similar, except for the use of slashes instead of backslashes, and a different specification of the Scala home directory.
Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland