本書の「まえがき」から引用する。
本書では読者がオブジェクト指向プログラミングに精通していることを前提としています。 また、関数型プログラミングの経験は問いません。また、1 つ以上のプログラミング言語の経験も前提とします。 Java、C#、Ruby、その他の言語の機能を例に挙げながら解説をしていきます。
本書で対応しているのは Scala 2.8 である。まえがきの xvi ページの脚注で、コードがサポートページからダウンロードできると書かれているが、
現在このサポートページは見つからない。代わりに、次のサポートページがある。
https://github.com/pso-ja/programming-scala/
ただ、いずれにせよ十年以上前の本である。現在の Scala Ver.3 では動作しないコードもある。
原著は第 3 版まで出版されている。この第 3 版では Scala 3 に対応しているようだ。下記を参照のこと。
https://deanwampler.github.io/books/programmingscala.html
たとえば、p.210 にある次のコードはエラーとなる。
// code-examples/Concurrency/simple-actor-script.scala import scala.actors.Actor class Redford extends Actor { def act() { println("A lot of what acting is, is paying attention.") } } val robert = new Redford robert.start
コンパイルするとこうなる。
PS C:\scala_programming\Concurrency> scalac .\simple-actor-script.scala -- [E040] Syntax Error: .\simple-actor-script.scala:6:12 ----------------------- 6 | def act() { | ^ | '=' expected, but '{' found -- [E103] Syntax Error: .\simple-actor-script.scala:12:0 ----------------------- 12 |robert.start |^^^^^^ |Illegal start of toplevel definition | | longer explanation available when compiling with `-explain` -- [E008] Not Found Error: .\simple-actor-script.scala:3:13 -------------------- 3 |import scala.actors.Actor | ^^^^^^^^^^^^ | value actors is not a member of scala 3 errors found
では Scala で並行処理をどのようにプログラミングすればいいのだろうか。Scala 3 自身がもつ機能を使うのならば、
Future を使うことになるだろう。たとえば、ここをみればいい(英語):
https://docs.scala-lang.org/scala3/book/concurrency.html
Scala でアクターモデルを採用するには Akka を使うことになるだろう。
Ver.3 では、XML との連携は標準では考慮されていないようだ。pp.229-230 のコードブロックを実行した結果である。
PS C:\scala_programming\XML\reading> scala .\from-string-script.scala -- [E008] Not Found Error: C:\scala_programming\XML\reading\.\from-string-script.scala:1:13 1 |import scala.xml._ | ^^^^^^^^^ | value xml is not a member of scala 1 error found Errors encountered during compilation
p.315 からアノテーションについて説明されている。ここでの例としては、「契約による設計」のプログラミングをサポートするためのアノテーションが取り上げられている。 しかし、ここで使われているツールキット Contract4J は、現在は使われていないようだ。技術の進歩は速い。
書名 | プログラミング Scala |
著者 | Dean Wampler, Alex Payne |
訳者 | 株式会社オージス総研 オブジェクトの広場編集部 |
発行日 | 2011 年 1 月 17 日 初版第 1 刷 |
発行所 | オライリー・ジャパン |
定価 | 3800 円(税別) |
サイズ | |
ISBN | 978-4-87311-481-1 |
その他 | 越谷市立図書館にて借りて読む |
まりんきょ学問所 > コンピュータの部屋 > Scala > Dean Wampler, Alex Payne:プログラミング Scala