Scala Tutorialsを読む 22-2

http://scalatutorials.com/tour/interactive_tour_of_scala_arrays.html

日付ズレすぎたので、リアルな時間で書いてきます。

  • Arrays in Scala map to Java primitive Arrays (e.g. Java's int is Scala's Array[Int], Java's String is Array[String] in Scala)

Scalaの配列はJavaのプリミティブな配列に対応します。(例えば JavaのintはScalaのArray[Int]、JavaのStringScalaでArray[String]です。

Scala Tutorialsを読む 21 Match as a Switch

http://scalatutorials.com/tour/interactive_tour_of_scala_match_as_a_switch.html

21 Match as a Switch

switchとしてのmatchか。as a でとしてって意味があるらしい。

Pattern matching will be familiar to anyone coming from a Haskell background,

パターンマッチはハスケルを背景にしている人には良く知られているであろう、

however it might look a bit weird at first for anyone coming from imperative languages.

命令型言語からの人にはパターンマッチは少し奇妙に見えるかもしれません。weirdは奇妙かJOJO's weird adventureなのかな。BIZARREか。

Pattern matching in it's most basic form, can look like an extended switch, with some differences:

最も基本的なパターンマッチは、switchを継承していると見る事ができますが、いくつかの違いがあります:

  • The match keyword comes after the variable (selection match compared to switch(selection)
  • matchキーワードは値の後ろに来ます(selection matchswitch(selection)と同等
  • There is no need for break;
  • break;は必要ありません。
  • There is no fall through
  • フォールスルーしません。
  • default case is case _ (or case x where x can be any lower case identifier, more about it in the next slides)
  • defaultのケースはcase _です。(もしくは case x のxはすべての小文字識別子が書け、次のスライドで詳しく説明します)

Pattern matching can be very powerful beyond a switch replacement, and will be explained in later slides

パターンマッチはswitchを置き換えるに留まらずとても強力な事が出来きるので、更なる説明を以降のスライドでします。

See Also opens in new page

新しいページを開いて参照

  • More on pattern matching
  • パターンマッチの詳細

Scala Tutorialsを読む 20 If

http://scalatutorials.com/tour/interactive_tour_of_scala_if.html

20 If

Conditions are almost the same as in imperative languages such as Java or C.

条件はほぼ、命令的な言語のJavaやCと同じです。

However one important thing to remember in Scala, is that everything is an expression, even an if block. しかしながらScalaではifブロックはすべて式であるという1つ重要な点を覚えてください。

The ternary operator ( condition _ truePart : falsePart) in Scala is simply if (condition) truePart else falsePart

Scalaの3項演算子( condition _ truePart : falsePart)は単に if (condition) truePart else falsePartです。

Scala Tutorialsを読む 19 Loops without loops

Scala Tutorialsを読む 19 Loops without loops

http://scalatutorials.com/tour/interactive_tour_of_scala_loops_without_loops.html

19 ループのないループ

The "Scala" way (or Functional way) of performing a sum of numbers.

数値の合計の計算のScalaの方法 (もしくは関数的な方法)です。

Many programming tasks can be written in Scala using similar concepts without the use

多くのプログラミングのタスクは明示的なwhileループを使わずにScalaのやり方で書けるでしょう。

Scala Tutorialsを読む 18 Loops using for

http://scalatutorials.com/tour/interactive_tour_of_scala_loops_using_for.html

今日は18 Loops using forをforを使ったループを読みます。 Scalaのforは、凄く高機能で高級な機能を持っているのですが、その触りで結構普通にループしています。

For loops in Scala are powerful and deserve a separate discussion.

ScalaのForループはパワフルであり議論を分ける価値があります。

But they can be used to mimic a c / Java like for loop as well.

しかし、Javaのforループと似たように簡単に使う事が出来ます。

See Also opens in new page

新しいページを開いて参照

  • More on for loops
  • forループの詳細

明日は、Loops without loops ループ無しのループです。なんか面白いタイトルですね。withoutとwithって良く出て来るなぁ。