Thursday, May 17, 2012

Scala Examples - Advanced


SourceDescription
addressbook.scalaAddress book to XHTML code (see also XML Processing)
callccInterpreter.scalaInterpreter with continuations using monads
fors.scalafor comprehensions (see also Sequence Comprehensions)
gadts.scalaGeneralised algebraic data types
lazyEvaluation.scalaLazy evaluation
message.scalaActors (see also Actors for Scala)
patterns.scalaPattern matching using case classes (see also Case Classes)
extractorPatterns.scalaPattern matching using extractors - a flexible way of matching objects with patterns
pingpong.scalaActors (see also Actors for Scala)
properties.scalaProperties
random.scalaClient/server application using Java sockets
simpleInterpreter.scalaSimple interpreter using monads
sort.scalaRecursive quicksort algorithm (imperative solution, see also Nested Functions)
sort1.scalaRecursive quicksort algorithm (functional solution)
timeofday.scalaProperties (see example 1 in § 4.2 of the Scala Language Specification)
vectors.scalaVector operations using views (see also Views)
brainf_ck.scalaA small Brainf*ck interpreter


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\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 sortobject. 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.

Other Scala examples

Finally, the following ressources contain Scala examples as well:
  • The Scala distribution contains a directory examples with other source examples.
  • The document Scala By Example (about 150 pages, available in PDF format) contains more advanced Scala examples.
  • The Scala Wiki contains many other code examples.

scala-lang.org

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments: on "Scala Examples - Advanced"

Post a Comment