@@ -2089,30 +2089,16 @@ in the `expr` following `do`.
2089
2089
If the ` expr ` is a [ path expression] ( #path-expressions ) , it is parsed as though it is a call expression.
2090
2090
If the ` expr ` is a [ field expression] ( #field-expressions ) , it is parsed as though it is a method call expression.
2091
2091
2092
- Additionally, any occurrence of a [ return expression] ( #return-expressions )
2093
- inside the ` block ` of a ` do ` expression is rewritten
2094
- as a reference to an (anonymous) flag set in the caller's environment,
2095
- which is checked on return from the ` expr ` and, if set,
2096
- causes a corresponding return from the caller.
2097
- In this way, the meaning of ` return ` statements in language built-in control blocks is preserved,
2098
- if they are rewritten using lambda functions and ` do ` expressions as abstractions.
2099
-
2100
- Therefore the two calls to ` f ` in this example are equivalent.
2101
- Both cause an early return from the caller's frame:
2092
+ In this example, both calls to ` f ` are equivalent:
2102
2093
2103
2094
~~~~
2104
2095
# fn f(f: fn(int)) { }
2105
2096
# fn g(i: int) { }
2106
2097
2107
- {
2108
- let mut _early_ret = false;
2109
- f(|j| { g(j); _early_ret = true; });
2110
- if _early_ret { return; }
2111
- }
2098
+ f(|j| g(j));
2112
2099
2113
2100
do f |j| {
2114
2101
g(j);
2115
- return;
2116
2102
}
2117
2103
~~~~
2118
2104
@@ -2130,7 +2116,15 @@ suited to passing the `block` function to a higher-order function implementing a
2130
2116
Like a ` do ` expression, a ` return ` expression inside a ` for ` expresison is rewritten,
2131
2117
to access a local flag that causes an early return in the caller.
2132
2118
2133
- Additionally, [ ` break ` ] ( #break-expressions ) and [ ` loop ` ] ( #loop-expressions ) expressions
2119
+ Additionally, any occurrence of a [ return expression] ( #return-expressions )
2120
+ inside the ` block ` of a ` for ` expression is rewritten
2121
+ as a reference to an (anonymous) flag set in the caller's environment,
2122
+ which is checked on return from the ` expr ` and, if set,
2123
+ causes a corresponding return from the caller.
2124
+ In this way, the meaning of ` return ` statements in language built-in control blocks is preserved,
2125
+ if they are rewritten using lambda functions and ` do ` expressions as abstractions.
2126
+
2127
+ Like ` return ` expressions, any [ ` break ` ] ( #break-expressions ) and [ ` loop ` ] ( #loop-expressions ) expressions
2134
2128
are rewritten inside ` for ` expressions, with a combination of local flag variables,
2135
2129
and early boolean-valued returns from the ` block ` function,
2136
2130
such that the meaning of ` break ` and ` loop ` is preserved in a primitive loop
@@ -2143,7 +2137,7 @@ An example a for loop:
2143
2137
# fn bar(f: foo) { }
2144
2138
# let a = 0, b = 0, c = 0;
2145
2139
2146
- let v: [foo] = [a, b, c];
2140
+ let v: & [foo] = & [a, b, c];
2147
2141
2148
2142
for v.each |e| {
2149
2143
bar(*e);
@@ -2530,7 +2524,7 @@ The kind of a vector type depends on the kind of its member type, as with other
2530
2524
An example of a vector type and its use:
2531
2525
2532
2526
~~~~
2533
- let v: &[int] = [7, 5, 3];
2527
+ let v: &[int] = & [7, 5, 3];
2534
2528
let i: int = v[2];
2535
2529
assert (i == 3);
2536
2530
~~~~
@@ -2701,16 +2695,16 @@ trait Printable {
2701
2695
fn to_str() -> ~str;
2702
2696
}
2703
2697
2704
- impl ~str : Printable {
2705
- fn to_str() -> ~str { self }
2698
+ impl int : Printable {
2699
+ fn to_str() -> ~str { int::to_str( self, 10) }
2706
2700
}
2707
2701
2708
- fn print(a: Printable) {
2702
+ fn print(a: @ Printable) {
2709
2703
io::println(a.to_str());
2710
2704
}
2711
2705
2712
2706
fn main() {
2713
- print(~"meow" as ~ Printable);
2707
+ print(@10 as @ Printable);
2714
2708
}
2715
2709
~~~~~~~~
2716
2710
0 commit comments