Skip to content

Commit 5835f96

Browse files
committed
---
yaml --- r: 37177 b: refs/heads/try c: 515f88f h: refs/heads/master i: 37175: a78a27a v: v3
1 parent 06fd02a commit 5835f96

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 09bb07bed9166105ea961a42b5fff7739ae0d2e9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
5-
refs/heads/try: fd85a0000a542a52f0fda3bd2f941fba452e0698
5+
refs/heads/try: 515f88f1c1ca5638c0ed0f64b7c17add45ae5db3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/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)