Skip to content

Commit 55713c2

Browse files
committed
---
yaml --- r: 35896 b: refs/heads/try2 c: 515f88f h: refs/heads/master v: v3
1 parent af9cc11 commit 55713c2

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: fd85a0000a542a52f0fda3bd2f941fba452e0698
8+
refs/heads/try2: 515f88f1c1ca5638c0ed0f64b7c17add45ae5db3
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/doc/rust.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,13 +2120,21 @@ do f |j| {
21202120
### For expressions
21212121

21222122
~~~~~~~~{.ebnf .gram}
2123-
for_expr : "for" pat "in" expr '{' block '}' ;
2123+
for_expr : "for" expr [ '|' ident_list '|' ] ? '{' block '}' ;
21242124
~~~~~~~~
21252125

2126-
A _for loop_ is controlled by a vector or string. The for loop bounds-checks
2127-
the underlying sequence *once* when initiating the loop, then repeatedly
2128-
executes the loop body with the loop variable referencing the successive
2129-
elements of the underlying sequence, one iteration per sequence element.
2126+
A _for expression_ is similar to a [`do` expression](#do-expressions),
2127+
in that it provides a special block-form of lambda expression,
2128+
suited to passing the `block` function to a higher-order function implementing a loop.
2129+
2130+
Like a `do` expression, a `return` expression inside a `for` expresison is rewritten,
2131+
to access a local flag that causes an early return in the caller.
2132+
2133+
Additionally, [`break`](#break-expressions) and [`loop`](#loop-expressions) expressions
2134+
are rewritten inside `for` expressions, with a combination of local flag variables,
2135+
and early boolean-valued returns from the `block` function,
2136+
such that the meaning of `break` and `loop` is preserved in a primitive loop
2137+
when rewritten as a `for` loop controlled by a higher order function.
21302138

21312139
An example a for loop:
21322140

@@ -2135,7 +2143,7 @@ An example a for loop:
21352143
# fn bar(f: foo) { }
21362144
# let a = 0, b = 0, c = 0;
21372145
2138-
let v: ~[foo] = ~[a, b, c];
2146+
let v: [foo] = [a, b, c];
21392147
21402148
for v.each |e| {
21412149
bar(*e);

0 commit comments

Comments
 (0)