Showing posts with label Scala Advanced. Show all posts
Showing posts with label Scala Advanced. Show all posts

Friday, July 6, 2012

Install Scala on MAC OS X ( LION )

Hello there, in this post I will share how to install Scala on your Mac Lion. First thing you need to do is download the latest Scala compiler. Click here and download the .tgz compiler package. I recommend downloading the.tgz file rather than .jar.

When the download completed, unpack and move it to your user home folder. For example, "/Users/your_user/". Once you moved it to the user's home folder, now create or modify your ".profile" files in your home folder. Open the Terminal and use Vim or Nano to add the line below to the end of file.
export PATH="/Users/your_user/scala/bin:$PATH"
Save and close the modified file. Now apply the changes using this command.
source .profile
Close the Terminal and reopen it to check the result. To verify whether the Scala working well, in the Terminal type in “Scala” and you should see the output like the quote below.
 
iMac-my:~ ogonbat$ scala
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala>


read more...

Monday, July 2, 2012

How to install Scala on Debian/Ubuntu (Scala 2.9.0.1, 2.8.1)

Update: Scala 2.9.0.1 (hotfixes to 2.9.0, released on May 12) was released on May 25, 2011. In this tip you can find a way how to install it (and older version - 2.8.1) onto yours Ubuntu/Debian box.
Ubuntu default apt repository gives us option to install only scala-2.7.7, but if you want to use latest version of scala (2.9.0.1 2.8.1 to date when this tip was written), so all what we need to do is this actions:

$ wget http://www.scala-lang.org/downloads/distrib/files/scala-2.9.0.1.tgz
$ tar zxf scala-2.9.0.1.tgz
$ sudo mv scala-2.9.0.1 /usr/share/scala

But if you need to install older (2.8.1) version of scala you need to run next commands:
 
$ wget http://www.scala-lang.org/downloads/distrib/files/scala-2.8.1.final.tgz
$ tar zxf scala-2.8.1.final.tgz
$ sudo mv scala-2.8.1.final /usr/share/scala


Ok, now you we need to make a few links to scala binary, scalac (scala compiler), fsc (fast scala compiler) and others scala executables:
$ sudo ln -s /usr/share/scala/bin/scala /usr/bin/scala
$ sudo ln -s /usr/share/scala/bin/scalac /usr/bin/scalac
$ sudo ln -s /usr/share/scala/bin/fsc /usr/bin/fsc
$ sudo ln -s /usr/share/scala/bin/sbaz /usr/bin/sbaz
$ sudo ln -s /usr/share/scala/bin/sbaz-setup /usr/bin/sbaz-setup
$ sudo ln -s /usr/share/scala/bin/scaladoc /usr/bin/scaladoc
$ sudo ln -s /usr/share/scala/bin/scalap /usr/bin/scalap

And how to uninstall (for both versions of scala):

$ sudo rm -rf /usr/share/scala /usr/bin/scala /usr/bin/scalac /usr/bin/fsc /usr/bin/sbaz /usr/bin/sbaz-setup /usr/bin/scaladoc /usr/bin/scalap
read more...

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
read more...