Hello Scala

特徴

インストール

http://www.scala-lang.org/ からダウンロード

>SET SCALA_HOME=d:\dev\scala-2.7.0
>SET PATH=%SCALA_HOME%\bin;%PATH%
>scalac -version
Scala code runner version 2.7.0-final -- (c) 2002-2008 LAMP/EPFL

ディレクトリの中身

bin
fsc.bat ?
sbaz.bat パッケージング
sbaz-setup.bat
scala.bat シェル
scalac.bat コンパイラ
scaladoc.bat scala版javadc
scalap.bat scala版javap?
doc


ドキュメントは2.7でなぜか削られているので、2.6.1をダウンロードしていれておくか
Webから必要なときに取得するひつようがある。

sbaz パッケージングのマニュアル。CPANとかPearみたいなもの 2.6.1 2.7
sbaz-setup sbazのsetup
scala-deve\scala\api ScalaDoc ×
scala-deve\scala\examples サンプル
scala-deve\scala\tools binのバッチの使い方 ×
scala-documentation 例題、チュートリアル、レファレンス。ともにPDF ×
lib
sbaz.jar パッケージング
sbaz-tests.jar パッケージングのテスト?
scala-compiler.jar コンパイラ
scala-dbc.jar デバッガー?
scala-decoder.jar アセンブルか?
scala-library.jar ライブラリ
meta


XMLで設定値を定義みたいだが何につかっているかは未調査

misc


scala-tool-supportにいろんなツールのサポート。Eclipse以外の人はつかうのかも。

src


libのsrcがjarで提供。

実行

>type HelloWorld.scala
object HelloWorld {
  def main(args: Array[String]): Unit = {
    System.out.println("Hello, Scala!")
  }
}

>scalac HelloWorld.scala

>scala HelloWorld
Hello, Scala!
>type HelloWorldSJIS.scala
object HelloWorld {
  def main(args: Array[String]): Unit = {
    System.out.println("Hello, Scala! 日本語")
  }
}

>scalac HelloWorldSJIS.scala

>scala HelloWorld
Hello, Scala! 日本語

e:\temp\scala>type HelloWorldUTF8.scala
object HelloWorld {
  def main(args: Array[String]): Unit = {
    System.out.println("Hello, Scala! 譌・譛ャ隱・)
  }
}

>scalac HelloWorldUTF8.scala
IO error while decoding HelloWorldUTF8.scala with windows-31j
Please try specifying another one using the -encoding option

>scalac -encoding UTF-8 HelloWorldUTF8.scala

>scala HelloWorld
Hello, Scala! 日本語


scala -e "print(\"hoge\")" は実行できるが
scalc xxxx.scala はどうも実行できないようだ。

>scala -e "print(\"hoge\")"
hoge
>scala HelloWorld.scala
(virtual file):1: error: block must end in result expression, not in definition
object Main {
   ^
one error found
!!!
discarding <script preamble>
discarding (fragment of HelloWorld.scala)


scalac -helpしてもなぜかscalacのヘルプになる?

>scala -help
scalac [ <option> ]... [<torun> <arguments>]

All options to scalac are allowed.  See scalac -help.

<torun>, if present, is an object or script file to run.
If no <torun> is present, run an interactive shell.

Option -howtorun allows explicitly specifying how to run <torun>:
    script: it is a script file
    object: it is an object name
    guess: (the default) try to guess

Option -i requests that a file be pre-loaded.  It is only
meaningful for interactive shells.

Option -e requests that its argument be executed as Scala code.

Option -savecompiled requests that the compiled script be saved
for future use.

Option -nocompdaemon requests that the fsc offline compiler not be used.

Option -Dproperty=value sets a Java system property.

なんでだろう?

雑感

言語仕様はいいけど、なんかとっつきづらい。
なんでvoidじゃなくてUnitなんだろうとか、import で * じゃなくて _ とか。