Skip to content

Commit ef70b76

Browse files
committed
auto merge of #10668 : vky/rust/closure-doc-update, r=alexcrichton
2 parents 4fe1296 + 9c6bba9 commit ef70b76

File tree

6 files changed

+56
-56
lines changed

6 files changed

+56
-56
lines changed

doc/po/ja/rust.md.po

+8-8
Original file line numberDiff line numberDiff line change
@@ -1817,10 +1817,10 @@ msgstr ""
18171817
#, no-wrap
18181818
msgid ""
18191819
"~~~~ {.xfail-test}\n"
1820-
"fn iter<T>(seq: &[T], f: &fn(T)) {\n"
1820+
"fn iter<T>(seq: &[T], f: |T|) {\n"
18211821
" for elt in seq.iter() { f(elt); }\n"
18221822
"}\n"
1823-
"fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {\n"
1823+
"fn map<T, U>(seq: &[T], f: |T| -> U) -> ~[U] {\n"
18241824
" let mut acc = ~[];\n"
18251825
" for elt in seq.iter() { acc.push(f(elt)); }\n"
18261826
" acc\n"
@@ -2404,7 +2404,7 @@ msgid ""
24042404
"trait Seq<T> {\n"
24052405
" fn len(&self) -> uint;\n"
24062406
" fn elt_at(&self, n: uint) -> T;\n"
2407-
" fn iter(&self, &fn(T));\n"
2407+
" fn iter(&self, |T|);\n"
24082408
"}\n"
24092409
"~~~~\n"
24102410
msgstr ""
@@ -4243,7 +4243,7 @@ msgid ""
42434243
"[function definitions](#functions) do not. The exact type of capture "
42444244
"depends on the [function type](#function-types) inferred for the lambda "
42454245
"expression. In the simplest and least-expensive form (analogous to a "
4246-
"```&fn() { }``` expression), the lambda expression captures its environment "
4246+
"```|| { }``` expression), the lambda expression captures its environment "
42474247
"by reference, effectively borrowing pointers to all outer variables "
42484248
"mentioned inside the function. Alternately, the compiler may infer that a "
42494249
"lambda expression should copy or move values (depending on their type.) "
@@ -4262,7 +4262,7 @@ msgstr ""
42624262
#, no-wrap
42634263
msgid ""
42644264
"~~~~\n"
4265-
"fn ten_times(f: &fn(int)) {\n"
4265+
"fn ten_times(f: |int|) {\n"
42664266
" let mut i = 0;\n"
42674267
" while i < 10 {\n"
42684268
" f(i);\n"
@@ -4455,7 +4455,7 @@ msgstr ""
44554455

44564456
#. type: Plain text
44574457
#: doc/rust.md:2339
4458-
msgid "~~~~ # fn f(f: &fn(int)) { } # fn g(i: int) { }"
4458+
msgid "~~~~ # fn f(f: |int|) { } # fn g(i: int) { }"
44594459
msgstr ""
44604460

44614461
#. type: Plain text
@@ -4481,7 +4481,7 @@ msgstr ""
44814481

44824482
#. type: Plain text
44834483
#: doc/rust.md:2352
4484-
msgid "~~~~ # fn k(x:int, f: &fn(int)) { } # fn l(i: int) { }"
4484+
msgid "~~~~ # fn k(x:int, f: |int|) { } # fn l(i: int) { }"
44854485
msgstr ""
44864486

44874487
#. type: Plain text
@@ -5483,7 +5483,7 @@ msgstr ""
54835483
#, no-wrap
54845484
msgid ""
54855485
"~~~~~~~\n"
5486-
"fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {\n"
5486+
"fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> ~[B] {\n"
54875487
" if xs.len() == 0 {\n"
54885488
" return ~[];\n"
54895489
" }\n"

doc/po/ja/tutorial.md.po

+14-14
Original file line numberDiff line numberDiff line change
@@ -3340,10 +3340,10 @@ msgstr ""
33403340

33413341
#. type: Plain text
33423342
#: doc/tutorial.md:1434
3343-
msgid "~~~~ fn call_closure_with_ten(b: &fn(int)) { b(10); }"
3343+
msgid "~~~~ fn call_closure_with_ten(b: |int|) { b(10); }"
33443344
msgstr ""
33453345
"~~~~\n"
3346-
"fn call_closure_with_ten(b: &fn(int)) { b(10); }"
3346+
"fn call_closure_with_ten(b: |int|) { b(10); }"
33473347

33483348
#. type: Plain text
33493349
#: doc/tutorial.md:1437
@@ -3400,11 +3400,11 @@ msgstr ""
34003400
#: doc/tutorial.md:1459
34013401
msgid ""
34023402
"There are several forms of closure, each with its own role. The most common, "
3403-
"called a _stack closure_, has type `&fn` and can directly access local "
3403+
"called a _stack closure_, has type `||` and can directly access local "
34043404
"variables in the enclosing scope."
34053405
msgstr ""
34063406
"クロージャにはいくつかの形態があり、それぞれに独自の役割があります。最も一般"
3407-
"的なのはスタッククロージャと呼ばれるもので、 `&fn` という型を持ち、外側のロー"
3407+
"的なのはスタッククロージャと呼ばれるもので、 `||` という型を持ち、外側のロー"
34083408
"カル変数に直接アクセスすることができます。"
34093409

34103410
#. type: Plain text
@@ -3531,27 +3531,27 @@ msgstr "## クロージャの互換性"
35313531
msgid ""
35323532
"Rust closures have a convenient subtyping property: you can pass any kind of "
35333533
"closure (as long as the arguments and return types match) to functions that "
3534-
"expect a `&fn()`. Thus, when writing a higher-order function that only calls "
3534+
"expect a `||`. Thus, when writing a higher-order function that only calls "
35353535
"its function argument, and does nothing else with it, you should almost "
3536-
"always declare the type of that argument as `&fn()`. That way, callers may "
3536+
"always declare the type of that argument as `||`. That way, callers may "
35373537
"pass any kind of closure."
35383538
msgstr ""
35393539
"Rust のクロージャは型の派生 (subtyping) という便利な性質を持っています。この"
3540-
"性質により、`&fn()` 型を期待する関数には (引数と戻り値の型が一致する限り) 任"
3540+
"性質により、`||` 型を期待する関数には (引数と戻り値の型が一致する限り) 任"
35413541
"意の種類のクロージャを渡すことができます。したがって、引数で渡された関数につ"
35423542
"いては呼び出すだけで他に何もしない高階関数を書くときには、ほぼすべてのケース"
3543-
"で引数の型を `&fn` と宣言するべきです。そうすることで、呼び出し元は任意の種類"
3543+
"で引数の型を `||` と宣言するべきです。そうすることで、呼び出し元は任意の種類"
35443544
"のクロージャを渡すことができるよになります。"
35453545

35463546
#. type: Plain text
35473547
#: doc/tutorial.md:1527
35483548
msgid ""
3549-
"~~~~ fn call_twice(f: &fn()) { f(); f(); } let closure = || { \"I'm a "
3549+
"~~~~ fn call_twice(f: ||) { f(); f(); } let closure = || { \"I'm a "
35503550
"closure, and it doesn't matter what type I am\"; }; fn function() { \"I'm a "
35513551
"normal function\"; } call_twice(closure); call_twice(function); ~~~~"
35523552
msgstr ""
35533553
"~~~~\n"
3554-
"fn call_twice(f: &fn()) { f(); f(); }\n"
3554+
"fn call_twice(f: ||) { f(); f(); }\n"
35553555
"let closure = || { \"I'm a closure, and it doesn't matter what type I am"
35563556
"\"; };\n"
35573557
"fn function() { \"I'm a normal function\"; }\n"
@@ -3598,7 +3598,7 @@ msgstr ""
35983598
#, no-wrap
35993599
msgid ""
36003600
"~~~~\n"
3601-
"fn each(v: &[int], op: &fn(v: &int)) {\n"
3601+
"fn each(v: &[int], op: |v: &int|) {\n"
36023602
" let mut n = 0;\n"
36033603
" while n < v.len() {\n"
36043604
" op(&v[n]);\n"
@@ -3622,7 +3622,7 @@ msgstr ""
36223622
#, no-wrap
36233623
msgid ""
36243624
"~~~~\n"
3625-
"# fn each(v: &[int], op: &fn(v: &int)) { }\n"
3625+
"# fn each(v: &[int], op: |v: &int|) { }\n"
36263626
"# fn do_some_work(i: &int) { }\n"
36273627
"each([1, 2, 3], |n| {\n"
36283628
" do_some_work(n);\n"
@@ -3644,7 +3644,7 @@ msgstr ""
36443644
#, no-wrap
36453645
msgid ""
36463646
"~~~~\n"
3647-
"# fn each(v: &[int], op: &fn(v: &int)) { }\n"
3647+
"# fn each(v: &[int], op: |v: &int|) { }\n"
36483648
"# fn do_some_work(i: &int) { }\n"
36493649
"do each([1, 2, 3]) |n| {\n"
36503650
" do_some_work(n);\n"
@@ -4011,7 +4011,7 @@ msgstr ""
40114011
#, no-wrap
40124012
msgid ""
40134013
"~~~~\n"
4014-
"fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {\n"
4014+
"fn map<T, U>(vector: &[T], function: |v: &T| -> U) -> ~[U] {\n"
40154015
" let mut accumulator = ~[];\n"
40164016
" for element in vector.iter() {\n"
40174017
" accumulator.push(function(element));\n"

doc/po/rust.md.pot

+8-8
Original file line numberDiff line numberDiff line change
@@ -1817,10 +1817,10 @@ msgstr ""
18171817
#, no-wrap
18181818
msgid ""
18191819
"~~~~ {.xfail-test}\n"
1820-
"fn iter<T>(seq: &[T], f: &fn(T)) {\n"
1820+
"fn iter<T>(seq: &[T], f: |T|) {\n"
18211821
" for elt in seq.iter() { f(elt); }\n"
18221822
"}\n"
1823-
"fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {\n"
1823+
"fn map<T, U>(seq: &[T], f: |T| -> U) -> ~[U] {\n"
18241824
" let mut acc = ~[];\n"
18251825
" for elt in seq.iter() { acc.push(f(elt)); }\n"
18261826
" acc\n"
@@ -2404,7 +2404,7 @@ msgid ""
24042404
"trait Seq<T> {\n"
24052405
" fn len(&self) -> uint;\n"
24062406
" fn elt_at(&self, n: uint) -> T;\n"
2407-
" fn iter(&self, &fn(T));\n"
2407+
" fn iter(&self, |T|);\n"
24082408
"}\n"
24092409
"~~~~\n"
24102410
msgstr ""
@@ -4230,7 +4230,7 @@ msgid ""
42304230
"[function definitions](#functions) do not. The exact type of capture "
42314231
"depends on the [function type](#function-types) inferred for the lambda "
42324232
"expression. In the simplest and least-expensive form (analogous to a "
4233-
"```&fn() { }``` expression), the lambda expression captures its environment "
4233+
"```|| { }``` expression), the lambda expression captures its environment "
42344234
"by reference, effectively borrowing pointers to all outer variables "
42354235
"mentioned inside the function. Alternately, the compiler may infer that a "
42364236
"lambda expression should copy or move values (depending on their type.) "
@@ -4249,7 +4249,7 @@ msgstr ""
42494249
#, no-wrap
42504250
msgid ""
42514251
"~~~~\n"
4252-
"fn ten_times(f: &fn(int)) {\n"
4252+
"fn ten_times(f: |int|) {\n"
42534253
" let mut i = 0;\n"
42544254
" while i < 10 {\n"
42554255
" f(i);\n"
@@ -4442,7 +4442,7 @@ msgstr ""
44424442

44434443
#. type: Plain text
44444444
#: doc/rust.md:2339
4445-
msgid "~~~~ # fn f(f: &fn(int)) { } # fn g(i: int) { }"
4445+
msgid "~~~~ # fn f(f: |int|) { } # fn g(i: int) { }"
44464446
msgstr ""
44474447

44484448
#. type: Plain text
@@ -4468,7 +4468,7 @@ msgstr ""
44684468

44694469
#. type: Plain text
44704470
#: doc/rust.md:2352
4471-
msgid "~~~~ # fn k(x:int, f: &fn(int)) { } # fn l(i: int) { }"
4471+
msgid "~~~~ # fn k(x:int, f: |int|) { } # fn l(i: int) { }"
44724472
msgstr ""
44734473

44744474
#. type: Plain text
@@ -5470,7 +5470,7 @@ msgstr ""
54705470
#, no-wrap
54715471
msgid ""
54725472
"~~~~~~~\n"
5473-
"fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {\n"
5473+
"fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> ~[B] {\n"
54745474
" if xs.len() == 0 {\n"
54755475
" return ~[];\n"
54765476
" }\n"

doc/po/tutorial.md.pot

+9-9
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,7 @@ msgstr ""
25582558

25592559
#. type: Plain text
25602560
#: doc/tutorial.md:1434
2561-
msgid "~~~~ fn call_closure_with_ten(b: &fn(int)) { b(10); }"
2561+
msgid "~~~~ fn call_closure_with_ten(b: |int|) { b(10); }"
25622562
msgstr ""
25632563

25642564
#. type: Plain text
@@ -2601,7 +2601,7 @@ msgstr ""
26012601
#: doc/tutorial.md:1459
26022602
msgid ""
26032603
"There are several forms of closure, each with its own role. The most common, "
2604-
"called a _stack closure_, has type `&fn` and can directly access local "
2604+
"called a _stack closure_, has type `||` and can directly access local "
26052605
"variables in the enclosing scope."
26062606
msgstr ""
26072607

@@ -2700,16 +2700,16 @@ msgstr ""
27002700
msgid ""
27012701
"Rust closures have a convenient subtyping property: you can pass any kind of "
27022702
"closure (as long as the arguments and return types match) to functions that "
2703-
"expect a `&fn()`. Thus, when writing a higher-order function that only calls "
2703+
"expect a `||`. Thus, when writing a higher-order function that only calls "
27042704
"its function argument, and does nothing else with it, you should almost "
2705-
"always declare the type of that argument as `&fn()`. That way, callers may "
2705+
"always declare the type of that argument as `||`. That way, callers may "
27062706
"pass any kind of closure."
27072707
msgstr ""
27082708

27092709
#. type: Plain text
27102710
#: doc/tutorial.md:1527
27112711
msgid ""
2712-
"~~~~ fn call_twice(f: &fn()) { f(); f(); } let closure = || { \"I'm a "
2712+
"~~~~ fn call_twice(f: ||) { f(); f(); } let closure = || { \"I'm a "
27132713
"closure, and it doesn't matter what type I am\"; }; fn function() { \"I'm a "
27142714
"normal function\"; } call_twice(closure); call_twice(function); ~~~~"
27152715
msgstr ""
@@ -2746,7 +2746,7 @@ msgstr ""
27462746
#, no-wrap
27472747
msgid ""
27482748
"~~~~\n"
2749-
"fn each(v: &[int], op: &fn(v: &int)) {\n"
2749+
"fn each(v: &[int], op: |v: &int|) {\n"
27502750
" let mut n = 0;\n"
27512751
" while n < v.len() {\n"
27522752
" op(&v[n]);\n"
@@ -2768,7 +2768,7 @@ msgstr ""
27682768
#, no-wrap
27692769
msgid ""
27702770
"~~~~\n"
2771-
"# fn each(v: &[int], op: &fn(v: &int)) { }\n"
2771+
"# fn each(v: &[int], op: |v: &int|) { }\n"
27722772
"# fn do_some_work(i: &int) { }\n"
27732773
"each([1, 2, 3], |n| {\n"
27742774
" do_some_work(n);\n"
@@ -2788,7 +2788,7 @@ msgstr ""
27882788
#, no-wrap
27892789
msgid ""
27902790
"~~~~\n"
2791-
"# fn each(v: &[int], op: &fn(v: &int)) { }\n"
2791+
"# fn each(v: &[int], op: |v: &int|) { }\n"
27922792
"# fn do_some_work(i: &int) { }\n"
27932793
"do each([1, 2, 3]) |n| {\n"
27942794
" do_some_work(n);\n"
@@ -3080,7 +3080,7 @@ msgstr ""
30803080
#, no-wrap
30813081
msgid ""
30823082
"~~~~\n"
3083-
"fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {\n"
3083+
"fn map<T, U>(vector: &[T], function: |v: &T| -> U) -> ~[U] {\n"
30843084
" let mut accumulator = ~[];\n"
30853085
" for element in vector.iter() {\n"
30863086
" accumulator.push(function(element));\n"

doc/rust.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following
950950
the function name.
951951

952952
~~~~ {.xfail-test}
953-
fn iter<T>(seq: &[T], f: &fn(T)) {
953+
fn iter<T>(seq: &[T], f: |T|) {
954954
for elt in seq.iter() { f(elt); }
955955
}
956-
fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {
956+
fn map<T, U>(seq: &[T], f: |T| -> U) -> ~[U] {
957957
let mut acc = ~[];
958958
for elt in seq.iter() { acc.push(f(elt)); }
959959
acc
@@ -1314,7 +1314,7 @@ These appear after the trait name, using the same syntax used in [generic functi
13141314
trait Seq<T> {
13151315
fn len(&self) -> uint;
13161316
fn elt_at(&self, n: uint) -> T;
1317-
fn iter(&self, &fn(T));
1317+
fn iter(&self, |T|);
13181318
}
13191319
~~~~
13201320

@@ -2607,7 +2607,7 @@ as an abbreviation for defining and capturing a separate function.
26072607
Significantly, lambda expressions _capture their environment_,
26082608
which regular [function definitions](#functions) do not.
26092609
The exact type of capture depends on the [function type](#function-types) inferred for the lambda expression.
2610-
In the simplest and least-expensive form (analogous to a ```&fn() { }``` expression),
2610+
In the simplest and least-expensive form (analogous to a ```|| { }``` expression),
26112611
the lambda expression captures its environment by reference,
26122612
effectively borrowing pointers to all outer variables mentioned inside the function.
26132613
Alternately, the compiler may infer that a lambda expression should copy or move values (depending on their type.)
@@ -2617,7 +2617,7 @@ In this example, we define a function `ten_times` that takes a higher-order func
26172617
and call it with a lambda expression as an argument.
26182618

26192619
~~~~
2620-
fn ten_times(f: &fn(int)) {
2620+
fn ten_times(f: |int|) {
26212621
let mut i = 0;
26222622
while i < 10 {
26232623
f(i);
@@ -2726,7 +2726,7 @@ If the `expr` is a [field expression](#field-expressions), it is parsed as thoug
27262726
In this example, both calls to `f` are equivalent:
27272727

27282728
~~~~
2729-
# fn f(f: &fn(int)) { }
2729+
# fn f(f: |int|) { }
27302730
# fn g(i: int) { }
27312731
27322732
f(|j| g(j));
@@ -2739,7 +2739,7 @@ do f |j| {
27392739
In this example, both calls to the (binary) function `k` are equivalent:
27402740

27412741
~~~~
2742-
# fn k(x:int, f: &fn(int)) { }
2742+
# fn k(x:int, f: |int|) { }
27432743
# fn l(i: int) { }
27442744
27452745
k(3, |j| l(j));
@@ -3241,7 +3241,7 @@ and the cast expression in `main`.
32413241
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
32423242

32433243
~~~~
3244-
fn map<A: Clone, B: Clone>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
3244+
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> ~[B] {
32453245
if xs.len() == 0 {
32463246
return ~[];
32473247
}

0 commit comments

Comments
 (0)