Movatterモバイル変換


[0]ホーム

URL:


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

Home

Scala Main Menu

Home »Code Examples » Simple Snippets

Scala Snippets

Created by admin on 2008-07-24. Updated: 2009-03-15, 18:38
SourceDescription
abstractTypes.scalaAn example of how abstract types are used in a program
bigint.scalaUser-defined integers, BigInts, are used seamlessly
complexOps.scalaOperators can be defined on user-defined classes, here complex numbers
for-yield.scalaAn example of thefor andyield constructs
extendBuiltins.scalaAdding "!" as a new method on integers
implicits.scalaDefine a new method 'sort' on arrays without changing their definition
maps.scalaMaps are easy to use in Scala
match.scalaUsing pattern matching to recognize command line arguments
primes.scalaA simple, although inefficient, way to calculate prime numbers
sum.scalaCalculates the sum of the arguments supplied on the command line
varargs.scalaJava 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.

If you are ready to explore more complicated examples, please continue to ourAdvanced Examples page.

Scala Quick Links

Featured News

User login


will be sent securely

Create new account

Retrieve lost password

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


[8]ページ先頭

©2009-2026 Movatter.jp