Skip to content

Commit 07fe2e1

Browse files
authored
Merge pull request #162 from tatsuya6502/variable-bindings-1.9
4.1. Variable Binding to (1.9)
2 parents fc1a896 + 5b35e31 commit 07fe2e1

File tree

3 files changed

+38
-83
lines changed

3 files changed

+38
-83
lines changed

1.9/ja/book/variable-bindings.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<!-- Virtually every non-'Hello World’ Rust program uses *variable bindings*. They -->
55
<!-- bind some value to a name, so it can be used later. `let` is -->
6-
<!-- used to introduce a binding, just like this: -->
6+
<!-- used to introduce a binding, like this: -->
77
事実上全ての「Hello World」でないRustのプログラムは *変数束縛* を使っています。
88
変数束縛は何らかの値を名前へと束縛するので、後でその値を使えます。
99
このように、 `let` が束縛を導入するのに使われています。
@@ -28,23 +28,23 @@ fn main() {
2828

2929
<!-- In many languages, a variable binding would be called a *variable*, but Rust’s -->
3030
<!-- variable bindings have a few tricks up their sleeves. For example the -->
31-
<!-- left-hand side of a `let` expression is a ‘[pattern][pattern]’, not just a -->
31+
<!-- left-hand side of a `let` statement is a ‘[pattern][pattern]’, not just a -->
3232
<!-- variable name. This means we can do things like: -->
3333
多くの言語では変数束縛は *変数* と呼ばれるでしょうが、Rustの変数束縛は多少皮を被せてあります。
34-
例えば、 `let` の左側の式は[パターン][pattern]」であって、ただの変数名ではありません。
35-
これはこのようなことが出来るということです
34+
例えば、 `let` 文の左側は[パターン][pattern]」であって、ただの変数名ではありません。
35+
これはこのようなことができるということです
3636

3737
```rust
3838
let (x, y) = (1, 2);
3939
```
4040

41-
<!-- After this expression is evaluated, `x` will be one, and `y` will be two. -->
41+
<!-- After this statement is evaluated, `x` will be one, and `y` will be two. -->
4242
<!-- Patterns are really powerful, and have [their own section][pattern] in the -->
43-
<!-- book. We don’t need those features for now, so we’ll just keep this in the back -->
43+
<!-- book. We don’t need those features for now, so we’ll keep this in the back -->
4444
<!-- of our minds as we go forward. -->
45-
パターン式が評価されたあと`x` は1になり、 `y` は2になります。
45+
この文が評価されたあと`x` は1になり、 `y` は2になります。
4646
パターンは本当に強力で、本書には[パターンのセクション][pattern]もあります。
47-
今のところこの機能は必要ないので頭の片隅に留めておいてだけいて下さい
47+
今のところこの機能は必要ないので頭の片隅に留めておいてだけいてください
4848

4949
[pattern]: patterns.html
5050

@@ -58,10 +58,10 @@ let (x, y) = (1, 2);
5858
<!-- out. -->
5959
Rustは静的な型付言語であり、前もって型を与えておいて、それがコンパイル時に検査されます。
6060
じゃあなぜ最初の例はコンパイルが通るのでしょう?ええと、Rustには「型推論」と呼ばれるものがあります。
61-
型推論が型が何であるか判断出来るなら、型を書く必要はなくなります。
61+
型推論が型が何であるか判断できるなら、型を書く必要はなくなります。
6262

6363
<!-- We can add the type if we want to, though. Types come after a colon (`:`): -->
64-
書きたいなら型を書くことも出来ます。型はコロン(`:`)のあとに書きます。
64+
書きたいなら型を書くこともできます。型はコロン(`:`)のあとに書きます。
6565

6666
```rust
6767
let x: i32 = 5;
@@ -94,7 +94,7 @@ fn main() {
9494
<!-- `let`. Including these kinds of comments is not idiomatic Rust, but we'll -->
9595
<!-- occasionally include them to help you understand what the types that Rust -->
9696
<!-- infers are. -->
97-
この注釈と `let` の時に使う記法の類似性に留意して下さい
97+
この注釈と `let` の時に使う記法の類似性に留意してください
9898
このようなコメントを書くのはRust的ではありませんが、時折理解の手助けのためにRustが推論する型をコメントで注釈します。
9999

100100
<!-- # Mutability -->
@@ -136,7 +136,7 @@ x = 10;
136136
<!-- something you may not have intended to mutate. If bindings were mutable by -->
137137
<!-- default, the compiler would not be able to tell you this. If you _did_ intend -->
138138
<!-- mutation, then the solution is quite easy: add `mut`. -->
139-
束縛がデフォルトでイミュータブルであるのは複合的な理由によるものですが、Rustの主要な焦点、安全性の一環だと考えることが出来ます
139+
束縛がデフォルトでイミュータブルであるのは複合的な理由によるものですが、Rustの主要な焦点、安全性の一環だと考えることができます
140140
もし `mut` を忘れたらコンパイラが捕捉して、変更するつもりでなかったものを変更した旨を教えてくれます。
141141
束縛がデフォルトでミュータブルだったらコンパイラはこれを捕捉できません。
142142
もし _本当に_ 変更を意図していたのなら話は簡単です。 `mut` をつけ加えればいいのです。
@@ -158,7 +158,7 @@ x = 10;
158158
Rustの束縛はもう1つ他の言語と異る点があります。束縛を使う前に値で初期化されている必要があるのです。
159159

160160
<!-- Let’s try it out. Change your `src/main.rs` file to look like this: -->
161-
試してみましょう。 `src/main.rs` をいじってこのようにしてみて下さい
161+
試してみましょう。 `src/main.rs` をいじってこのようにしてみてください
162162

163163
```rust
164164
fn main() {
@@ -170,8 +170,8 @@ fn main() {
170170

171171
<!-- You can use `cargo build` on the command line to build it. You’ll get a -->
172172
<!-- warning, but it will still print "Hello, world!": -->
173-
コマンドラインで `cargo build` を使ってビルド出来ます
174-
警告が出ますが、それでもまだ「Hello, world!」は印字されます
173+
コマンドラインで `cargo build` を使ってビルドできます
174+
警告が出ますが、それでもまだ「Hello, world!」は表示されます
175175

176176
```text
177177
Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
@@ -186,7 +186,7 @@ src/main.rs:2 let x: i32;
186186
<!-- however. Let’s do that. Change your program to look like this: -->
187187
Rustは一度も使われない変数について警告を出しますが、一度も使われないので人畜無害です。
188188
ところがこの `x` を使おうとすると事は一変します。やってみましょう。
189-
プログラムをこのように変更して下さい
189+
プログラムをこのように変更してください
190190

191191
```rust,ignore
192192
fn main() {
@@ -197,7 +197,7 @@ fn main() {
197197
```
198198

199199
<!-- And try to build it. You’ll get an error: -->
200-
そしてビルドしてみて下さい。このようなエラーが出る筈です
200+
そしてビルドしてみてください。このようなエラーが出るはずです
201201

202202
```bash
203203
$ cargo build
@@ -224,20 +224,20 @@ Rustでは未初期化の値を使うことは許されていません。
224224
<!-- in the middle of a string." We add a comma, and then `x`, to indicate that we -->
225225
<!-- want `x` to be the value we’re interpolating. The comma is used to separate -->
226226
<!-- arguments we pass to functions and macros, if you’re passing more than one. -->
227-
印字する文字列に2つの波括弧(`{}`、口髭という人もいます…(訳注: 海外の顔文字は横になっているので首を傾けて `{` を眺めてみて下さい。また、日本語だと「中括弧」と呼ぶ人もいますね))を入れました。
228-
Rustはこれを何かの値を入れて(interpolate、インターポーレート)くれという要求だと解釈します
229-
*文字列インターポーレーション* (String interpolation)はコンピュータサイエンスの用語で、「文字列の中に差し込む」という意味です。
230-
その後に続けてカンマ、そして `x` を置いて `x` がインターポーレートしようとしている値だと指示しています
227+
表示する文字列に2つの波括弧(`{}`、口髭という人もいます…(訳注: 海外の顔文字は横になっているので首を傾けて `{` を眺めてみてください。また、日本語だと「中括弧」と呼ぶ人もいますね))を入れました。
228+
Rustはこれを、何かの値で補間(interpolate)してほしいのだと解釈します
229+
*文字列補間* (string interpolation)はコンピュータサイエンスの用語で、「文字列の間に差し込む」という意味です。
230+
その後に続けてカンマ、そして `x` を置いて `x` が補間に使う値だと指示しています
231231
カンマは2つ以上の引数を関数やマクロに渡す時に使われます。
232232

233-
<!-- When you just use the curly braces, Rust will attempt to display the value in a -->
233+
<!-- When you use the curly braces, Rust will attempt to display the value in a -->
234234
<!-- meaningful way by checking out its type. If you want to specify the format in a -->
235235
<!-- more detailed manner, there are a [wide number of options available][format]. -->
236-
<!-- For now, we'll just stick to the default: integers aren't very complicated to -->
236+
<!-- For now, we'll stick to the default: integers aren't very complicated to -->
237237
<!-- print. -->
238-
単に波括弧だけを使った時は、Rustはインターポーレートされる値の型を調べて意味のある方法で表示しようとします
239-
フォーマットをさらに詳しく指定したいなら[数多くのオプションが利用出来ます][format]
240-
とりあえずのところ、デフォルトに従いましょう。整数の印字はそれほど複雑ではありません
238+
波括弧を使うと、Rustは補間に使う値の型を調べて意味のある方法で表示しようとします
239+
フォーマットをさらに詳しく指定したいなら[数多くのオプションが利用できます][format]
240+
とりあえずのところ、デフォルトに従いましょう。整数の表示はそれほど複雑ではありません
241241

242242
[format]: ../std/fmt/index.html
243243

@@ -253,7 +253,7 @@ Rustはこれを何かの値を入れて(interpolate、インターポーレー
253253
束縛に話を戻しましょう。変数束縛にはスコープがあります。変数束縛は定義されたブロック内でしか有効でありません。
254254
ブロックは `{``}` に囲まれた文の集まりです。関数定義もブロックです!
255255
以下の例では異なるブロックで有効な2つの変数束縛、 `x``y` を定義しています。
256-
`x``fn main() {}` ブロックの中でアクセス可能ですが、 `y` は内側のブロックからのみアクセス出来ます
256+
`x``fn main() {}` ブロックの中でアクセス可能ですが、 `y` は内側のブロックからのみアクセスできます
257257

258258

259259
```rust,ignore
@@ -272,8 +272,8 @@ fn main() {
272272
<!-- 3", but this example cannot be compiled successfully, because the second -->
273273
<!-- `println!` cannot access the value of `y`, since it is not in scope anymore. -->
274274
<!-- Instead we get this error: -->
275-
最初の `println!` は「The value of x is 17 and the value of y is 3」(訳注: 「xの値は17でyの値は3」)と印字する筈ですが
276-
2つめの `println!``y` がもうスコープにいないため `y` にアクセス出来ないのでこの例はコンパイル出来ません
275+
最初の `println!` は「The value of x is 17 and the value of y is 3」(訳注: 「xの値は17でyの値は3」)と表示するはずですが
276+
2つめの `println!``y` がもうスコープにいないため `y` にアクセスできないのでこの例はコンパイルできません
277277
代わりに以下のようなエラーが出ます。
278278

279279
```bash
@@ -298,31 +298,31 @@ To learn more, run the command again with --verbose.
298298
<!-- Additionally, variable bindings can be shadowed. This means that a later -->
299299
<!-- variable binding with the same name as another binding, that's currently in -->
300300
<!-- scope, will override the previous binding. -->
301-
さらに加えて、変数束縛は覆い隠すことが出来ます(訳注: このことをシャドーイングと言います)。
301+
さらに加えて、変数束縛は覆い隠すことができます(訳注: このことをシャドーイングと言います)。
302302
つまり後に出てくる同じ名前の変数束縛があるとそれがスコープに入り、以前の束縛を上書きするのです。
303303

304304
```rust
305305
let x: i32 = 8;
306306
{
307307
# // println!("{}", x); // Prints "8"
308-
println!("{}", x); // "8"を印字する
308+
println!("{}", x); // "8"を表示する
309309
let x = 12;
310310
# // println!("{}", x); // Prints "12"
311-
println!("{}", x); // "12"を印字する
311+
println!("{}", x); // "12"を表示する
312312
}
313313
# // println!("{}", x); // Prints "8"
314-
println!("{}", x); // "8"を印字する
314+
println!("{}", x); // "8"を表示する
315315
let x = 42;
316316
# // println!("{}", x); // Prints "42"
317-
println!("{}", x); // "42"を印字する
317+
println!("{}", x); // "42"を表示する
318318
```
319319

320320
<!-- Shadowing and mutable bindings may appear as two sides of the same coin, but -->
321321
<!-- they are two distinct concepts that can't always be used interchangeably. For -->
322322
<!-- one, shadowing enables us to rebind a name to a value of a different type. It -->
323323
<!-- is also possible to change the mutability of a binding. -->
324-
シャドーイングとミュータブルな束縛はコインの表と裏のように見えるかもしれませんが、それぞれ独立な概念であり互いに代用が出来ないケースがあります
325-
その1つにシャドーイングは同じ名前に違う型の値を再束縛することが出来ます
324+
シャドーイングとミュータブルな束縛はコインの表と裏のように見えるかもしれませんが、それぞれ独立な概念であり互いに代用ができないケースがあります
325+
その1つにシャドーイングは同じ名前に違う型の値を再束縛することができます
326326

327327
```rust
328328
let mut x: i32 = 1;

TranslationTable.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
| interior | 内側の
102102
| install | インストール
103103
| installer | インストーラ
104-
| interpolate | インターポーレートする
105-
| interpolation | インターポーレーション
104+
| interpolate | 補間する
105+
| (string) interpolation | (文字列)補間
106106
| Intrinsics | Intrinsic
107107
| key | キー
108108
| keyword | キーワード

diff-1.6.0..1.9.0/src/doc/book/variable-bindings.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)