Source | Description |
---|---|
abstractTypes.scala [1] | An example of how abstract types are used in a program |
bigint.scala [2] | User-defined integers, BigInts, are used seamlessly |
complexOps.scala [3] | Operators can be defined on user-defined classes, here complex numbers |
for-yield.scala [4] | An example of the for and yield constructs |
extendBuiltins.scala [5] | Adding "!" as a new method on integers |
implicits.scala [6] | Define a new method 'sort' on arrays without changing their definition |
maps.scala [7] | Maps are easy to use in Scala |
match.scala [8] | Using pattern matching to recognize command line arguments |
primes.scala [9] | A simple, although inefficient, way to calculate prime numbers |
sum.scala [10] | Calculates the sum of the arguments supplied on the command line |
varargs.scala [11] | Java varargs can be easily used in Scala as well |
To compile and run on Windows one of the above Scala programs, let's say sort.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 is examples.sort
where examples
is the name of the package containing the sort
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.
Links:
[1] http://www.scala-lang.org/node/222
[2] http://www.scala-lang.org/node/223
[3] http://www.scala-lang.org/node/224
[4] http://www.scala-lang.org/node/225
[5] http://www.scala-lang.org/node/226
[6] http://www.scala-lang.org/node/227
[7] http://www.scala-lang.org/node/228
[8] http://www.scala-lang.org/node/229
[9] http://www.scala-lang.org/node/230
[10] http://www.scala-lang.org/node/231
[11] http://www.scala-lang.org/node/232
[12] http://www.scala-lang.org/node/44