From f749e02964f2155db205a66c60e1cf6d242a5580 Mon Sep 17 00:00:00 2001 From: Taketo Iseki Date: Mon, 1 Jul 2019 20:14:23 +0900 Subject: [PATCH 1/5] translate tour/automatic-closures into Japanese --- _ja/tour/automatic-closures.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/_ja/tour/automatic-closures.md b/_ja/tour/automatic-closures.md index 29ae0a8c00..3bb7fa6935 100644 --- a/_ja/tour/automatic-closures.md +++ b/_ja/tour/automatic-closures.md @@ -1,6 +1,6 @@ --- layout: tour -title: Automatic Type-Dependent Closure Construction +title: 型依存クロージャの自動構築 language: ja discourse: true @@ -8,9 +8,9 @@ discourse: true partof: scala-tour --- -Scala allows parameterless function names as parameters of methods. When such a method is called, the actual parameters for parameterless function names are not evaluated and a nullary function is passed instead which encapsulates the computation of the corresponding parameter (so-called *call-by-name* evaluation). +Scalaはメソッドのパラメータにパラメータを受け取らない関数名が使えます。このようなメソッドが呼び出される時、パラメータを受け取らない関数名は実際に評価されず、代わりに対応するパラメーターの処理をカプセル化した、引数を取らない関数が渡されます(そのため *名前渡し*評価と呼ばれます)。 -The following code demonstrates this mechanism: +以下のコードはこの仕組みを説明しています。 object TargetTest1 extends Application { def whileLoop(cond: => Boolean)(body: => Unit): Unit = @@ -25,11 +25,11 @@ The following code demonstrates this mechanism: } } -The function whileLoop takes two parameters `cond` and `body`. When the function is applied, the actual parameters do not get evaluated. But whenever the formal parameters are used in the body of `whileLoop`, the implicitly created nullary functions will be evaluated instead. Thus, our method `whileLoop` implements a Java-like while-loop with a recursive implementation scheme. +関数 whileLoop は2つのパラメータ`cond`と`body`を受け取ります。関数が適用される時、実際のパラメータは評価されません。しかし形式上のパラメータが`whileLoop`の本体内で使われる度に、暗黙に生成された引数の無い関数が代わりに評価されます。このようにメソッド`whileLoop`はJavaのようなwhileループを再帰的な実装案で実装しています。 -We can combine the use of [infix/postfix operators](operators.html) with this mechanism to create more complex statements (with a nice syntax). +[中置/後置 演算子](operators.html)とこのメカニズムを組み合わせ利用し、より複雑な式を(より良い構文で)が作れます。 -Here is the implementation of a loop-unless statement: +こちらがloop-unless式の実装です。 object TargetTest2 extends Application { def loop(body: => Unit): LoopUnlessCond = @@ -46,9 +46,9 @@ Here is the implementation of a loop-unless statement: i -= 1 } unless (i == 0) } -The `loop` function just accepts a body of a loop and returns an instance of class `LoopUnlessCond` (which encapsulates this body object). Note that the body didn't get evaluated yet. Class `LoopUnlessCond` has a method `unless` which we can use as a *infix operator*. This way, we achieve a quite natural syntax for our new loop: `loop { < stats > } unless ( < cond > )`. +この`loop`関数はループ処理の本体を受け取り、クラス`LoopUnlessCond`(bodyのオブジェクトをカプセル化する)のインスタンスを返すだけです。bodyはまだ評価されていないことに気をつけてください。クラス`LoopUnlessCond`は中置演算子として使えるメソッド`unless`を持ちます。このようにより自然な構文で新しいループ処理`loop { < stats > } unless ( < cond > )`を作れます。 -Here's the output when `TargetTest2` gets executed: +こちらが`TargetTest2`を実行した時の出力です。 i = 10 i = 9 From 9a29e0c37f857dca7a712fd43b01ba4379b5ef15 Mon Sep 17 00:00:00 2001 From: take2 Date: Wed, 3 Jul 2019 01:09:30 +0900 Subject: [PATCH 2/5] Update _ja/tour/automatic-closures.md Co-Authored-By: Masanori Fujita --- _ja/tour/automatic-closures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_ja/tour/automatic-closures.md b/_ja/tour/automatic-closures.md index 3bb7fa6935..3d21d052cd 100644 --- a/_ja/tour/automatic-closures.md +++ b/_ja/tour/automatic-closures.md @@ -8,7 +8,7 @@ discourse: true partof: scala-tour --- -Scalaはメソッドのパラメータにパラメータを受け取らない関数名が使えます。このようなメソッドが呼び出される時、パラメータを受け取らない関数名は実際に評価されず、代わりに対応するパラメーターの処理をカプセル化した、引数を取らない関数が渡されます(そのため *名前渡し*評価と呼ばれます)。 +Scalaはメソッドのパラメータとしてパラメータ無しの関数名を渡せます。そのようなメソッドが呼ばれると、パラメータ無しの関数名は実際に評価されず、代わりに対応するパラメーターの処理をカプセル化した、引数無しの関数が渡されます(いわゆる *名前渡し*評価です)。 以下のコードはこの仕組みを説明しています。 From 35e386e93a6aa6465514fab1f652501c31e6f166 Mon Sep 17 00:00:00 2001 From: take2 Date: Wed, 3 Jul 2019 01:09:55 +0900 Subject: [PATCH 3/5] Update _ja/tour/automatic-closures.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 実装案 => 方法 Co-Authored-By: Masanori Fujita --- _ja/tour/automatic-closures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_ja/tour/automatic-closures.md b/_ja/tour/automatic-closures.md index 3d21d052cd..1d190d4cae 100644 --- a/_ja/tour/automatic-closures.md +++ b/_ja/tour/automatic-closures.md @@ -25,7 +25,7 @@ Scalaはメソッドのパラメータとしてパラメータ無しの関数名 } } -関数 whileLoop は2つのパラメータ`cond`と`body`を受け取ります。関数が適用される時、実際のパラメータは評価されません。しかし形式上のパラメータが`whileLoop`の本体内で使われる度に、暗黙に生成された引数の無い関数が代わりに評価されます。このようにメソッド`whileLoop`はJavaのようなwhileループを再帰的な実装案で実装しています。 +関数 whileLoop は2つのパラメータ`cond`と`body`を受け取ります。関数が適用される時、実際のパラメータは評価されません。しかし形式上のパラメータが`whileLoop`の本体内で使われる度に、暗黙に生成された引数の無い関数が代わりに評価されます。このようにメソッド`whileLoop`はJavaのようなwhileループを再帰的な方法で実装しています。 [中置/後置 演算子](operators.html)とこのメカニズムを組み合わせ利用し、より複雑な式を(より良い構文で)が作れます。 From 6a0d6ea2492a0ba551ac9db86277354d4a17be48 Mon Sep 17 00:00:00 2001 From: take2 Date: Wed, 3 Jul 2019 01:10:14 +0900 Subject: [PATCH 4/5] Update _ja/tour/automatic-closures.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 不要ながを削除 Co-Authored-By: Masanori Fujita --- _ja/tour/automatic-closures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_ja/tour/automatic-closures.md b/_ja/tour/automatic-closures.md index 1d190d4cae..a12b8e8742 100644 --- a/_ja/tour/automatic-closures.md +++ b/_ja/tour/automatic-closures.md @@ -27,7 +27,7 @@ Scalaはメソッドのパラメータとしてパラメータ無しの関数名 関数 whileLoop は2つのパラメータ`cond`と`body`を受け取ります。関数が適用される時、実際のパラメータは評価されません。しかし形式上のパラメータが`whileLoop`の本体内で使われる度に、暗黙に生成された引数の無い関数が代わりに評価されます。このようにメソッド`whileLoop`はJavaのようなwhileループを再帰的な方法で実装しています。 -[中置/後置 演算子](operators.html)とこのメカニズムを組み合わせ利用し、より複雑な式を(より良い構文で)が作れます。 +[中置/後置 演算子](operators.html)とこのメカニズムを組み合わせ利用し、より複雑な式を(より良い構文で)作れます。 こちらがloop-unless式の実装です。 From 3d67daf99b56fbef8c7dd45d847f23caeec12548 Mon Sep 17 00:00:00 2001 From: take2 Date: Wed, 3 Jul 2019 01:14:37 +0900 Subject: [PATCH 5/5] Update _ja/tour/automatic-closures.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bodyは素直に概念の説明にした方が日本語が読みやすい Co-Authored-By: Masanori Fujita --- _ja/tour/automatic-closures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_ja/tour/automatic-closures.md b/_ja/tour/automatic-closures.md index a12b8e8742..0b865b72fd 100644 --- a/_ja/tour/automatic-closures.md +++ b/_ja/tour/automatic-closures.md @@ -46,7 +46,7 @@ Scalaはメソッドのパラメータとしてパラメータ無しの関数名 i -= 1 } unless (i == 0) } -この`loop`関数はループ処理の本体を受け取り、クラス`LoopUnlessCond`(bodyのオブジェクトをカプセル化する)のインスタンスを返すだけです。bodyはまだ評価されていないことに気をつけてください。クラス`LoopUnlessCond`は中置演算子として使えるメソッド`unless`を持ちます。このようにより自然な構文で新しいループ処理`loop { < stats > } unless ( < cond > )`を作れます。 +この`loop`関数はループ処理の本体を受け取り、クラス`LoopUnlessCond`(この処理の本体をカプセル化する)のインスタンスを返すだけです。処理の本体はまだ評価されていないことに気をつけてください。クラス`LoopUnlessCond`は *中置演算子* として使えるメソッド`unless`を持ちます。このように、新しいループ処理: `loop { < stats > } unless ( < cond > )`のとても自然な構文を作れます。 こちらが`TargetTest2`を実行した時の出力です。