Java.use(better, Scala); S4(E1) 15パズル
#Scalaの栞
◉ Java.use(better, Scala); Season4(Episode1) 15パズル
私たちの人生は
私たちが費やした努力だけの価値がある
《目的》同じアプリケーションを異なるプログラミング言語 Java/Jython/Scala で作成する過程(作譜:プログラミング)を通して、言語の違いに依らない手法(算譜:プログラム)を紹介します。
《動機》ともすると、プログラミング言語の違いに目を奪われて、プログラムの本質を見失いがちです。同じアプリケーションを異なるプログラミング言語で作成するのは、そこに意義があります。
課題:15パズル
前回の「ファインダー」と違って、今回の「ゲーム」は実用的なツールではありませんが、興味深いプログラミングの話題を提供します。今回は、Java 版のゲームを、Scala で再構成する過程を紹介します。
開け胡麻
対話形式で利用する
Scala を対話形式で利用するには、コマンド scala を実行します。すると、
$ scala Welcome to Scala version 2.9.0.final (Java HotSpot(TM) Client VM, Java 1.5.0_13). Type in expressions to have them evaluated. Type :help for more information. scala>
数行のメッセージ(Scala/Java のバージョン情報などを含む)に続いて、利用者の入力を促すプロンプト記号 scala> が現れます。これに続いてコードの断片を入力すると、その動作を確認できます。
サブコマンド :help
出力されるメッセージの末尾には「:help を入力すると、詳しい情報が得られる」とあります。そこで、サブコマンド:help を入力します。
scala> :help All commands can be abbreviated, e.g. :he instead of :help. Those marked with a * have more detailed help, e.g. :help imports. :cpadd a jar or directory to the classpath :help [command] print this summary or command-specific help :history [num] show the history (optional num is commands to show) :h? search the history :imports [name name ...] show import history, identifying sources of names :implicits [-v] show the implicits in scope :javap <path|class> disassemble a file or class name :keybindings show how ctrl-[A-Z] and other keys are bound :load load and interpret a Scala file :paste enter paste mode: all input up to ctrl-D compiled together :power enable power user mode :quit exit the interpreter :replay reset execution and replay all previous commands :sh run a shell command (result is implicitly => List[String]) :silent disable/enable automatic printing of results :type display the type of an expression without evaluating it
各項目の詳細は後述するので、話を先に進めます。
2021/02/14 12:25
【変更履歴】
- 初稿: 2012/12/18
- 更新: 2013/12/10