「Scala」の版間の差分

提供: FreeBSD入門
移動: 案内検索
(ページの作成:「Scala とは、Scalable Lanaugeの接頭辞です。Scalaは、オブジェクト指向言語と関数型言語の特徴を統合した言語です。 '''読...」)
(相違点なし)

2014年3月21日 (金) 20:44時点における版

Scala とは、Scalable Lanaugeの接頭辞です。Scalaは、オブジェクト指向言語と関数型言語の特徴を統合した言語です。

読み方

Scala
すから

概要

Scala

インストール

pkgコマンドでインストールする場合

sudo pkg install

インストール例

% sudo pkg install scala
Updating repository catalogue
The following 9 packages will be installed:
 
        Installing recordproto: 1.14.2
        Installing xbitmaps: 1.1.1
        Upgrading freetype2: 2.5.2 -> 2.5.3
        Installing javavmwrapper: 2.4_3
        Installing java-zoneinfo: 2013.i
        Installing libXtst: 1.2.2
        Installing open-motif: 2.3.4
        Installing openjdk6: b30_2,1
        Installing scala: 2.10.3
 
The installation will require 208 MB more space
 
83 MB to be downloaded
 
Proceed with installing packages [y/N]: y
recordproto-1.14.2.txz                 100% 4652     4.5KB/s   4.5KB/s   00:00
xbitmaps-1.1.1.txz                     100%   22KB  22.4KB/s  22.4KB/s   00:00
freetype2-2.5.3.txz                    100%  448KB  74.7KB/s 118.1KB/s   00:06
javavmwrapper-2.4_3.txz                100%   18KB  17.7KB/s  17.7KB/s   00:00
java-zoneinfo-2013.i.txz               100%   75KB  75.4KB/s  75.4KB/s   00:01
libXtst-1.2.2.txz                      100%   21KB  20.5KB/s  20.5KB/s   00:00
open-motif-2.3.4.txz                   100% 7562KB  83.1KB/s 112.5KB/s   01:31
openjdk6-b30_2,1.txz                   100%   47MB  74.6KB/s 128.2KB/s   10:40
scala-2.10.3.txz                       100%   29MB  93.0KB/s 370.4KB/s   05:16
Checking integrity... done
[1/9] Installing recordproto-1.14.2... done
[2/9] Installing xbitmaps-1.1.1... done
[3/9] Upgrading freetype2 from 2.5.2 to 2.5.3... done
[4/9] Installing javavmwrapper-2.4_3... done
[5/9] Installing java-zoneinfo-2013.i... done
[6/9] Installing libXtst-1.2.2... done
[7/9] Installing open-motif-2.3.4... done
[8/9] Installing openjdk6-b30_2,1... done
[9/9] Installing scala-2.10.3... done
======UNIQ715040425045b45a-h-3--QINU================================================================
 
This OpenJDK implementation requires fdescfs(5) mounted on /dev/fd and
procfs(5) mounted on /proc.
 
If you have not done it yet, please do the following:
 
        mount -t fdescfs fdesc /dev/fd
        mount -t procfs proc /proc
 
To make it permanent, you need the following lines in /etc/fstab:
 
        fdesc   /dev/fd         fdescfs         rw      0       0
        proc    /proc           procfs          rw      0       0
 
======UNIQ715040425045b45a-h-4--QINU================================================================

設定

OpenJDSKの設定

/etc/fstab

/etc/fstab に以下の設定を加えます。

fdesc   /dev/fd         fdescfs         rw      0       0
proc    /proc           procfs          rw      0       0

設定を反映させるには、以下のコマンドを実行します。

sudo mount -a

コマンドラインで一時的に設定する場合には、以下のコマンドを実行します。

mount -t fdescfs fdesc /dev/fd
mount -t procfs proc /proc

シェルの設定

環境変数に JAVA_HOME を設定します。

sh系

export JAVA_HOME=/usr/local/openjdk6

csh系

setenv JAVA_HOME /usr/local/openjdk6

使い方

コマンドラインオプション

$ scala -help
Usage: scala <options> [<script|class|object|jar> <arguments>]
   or  scala -help
 
All options to scalac (see scalac -help) are also allowed.
The first given argument other than options to scala designates
what to run.  Runnable targets are:
 
  - a file containing scala source
  - the name of a compiled class
  - a runnable jar file with a valid Main-Class attribute
  - or if no argument is given, the repl (interactive shell) is started
 
Options to scala which reach the java runtime:
 
 -Dname=prop  passed directly to java to set system properties
 -J<arg>      -J is stripped and <arg> passed to java as-is
 -nobootcp    do not put the scala jars on the boot classpath (slower)
 
Other startup options:
 
 -howtorun    what to run <script|object|jar|guess> (default: guess)
 -i <file>    preload <file> before starting the repl
 -e <string>  execute <string> as if entered in the repl
 -save        save the compiled script in a jar for future use
 -nc          no compilation daemon: do not use the fsc offline compiler
 
A file argument will be run as a scala script unless it contains only
self-contained compilation units (classes and objects) and exactly one
runnable main method.  In that case the file will be compiled and the
main method invoked.  This provides a bridge between scripts and standard
scala source.
 
 
Options for plugin 'continuations':
  -P:continuations:enable        Enable continuations

ScalaでのHello Worldプログラム Hello.scala

"Hello World"プログラム、Hello.scalaは、以下のとおりです。

object Hello {
        def main(args: Array[String]) {
                println("Hello");
        }
}

コンパイルせずに実行する例です。

$ scala Hello.scala
Hello

コンパイルして実行する例です。

$ scalac Hello.scala
$ scala Hello
Hello

scalaからロードして実行する例です。

$ scala
Welcome to Scala version 2.10.3 (OpenJDK 64-Bit Server VM, Java 1.6.0_32).
Type in expressions to have them evaluated.
Type :help for more information.
 
scala> :load Hello.scala
Loading Hello.scala...
defined module Hello
 
scala> Hello.main(Array())
Hello
 
scala>

関連項目

  • Scala