@@ -1671,6 +1671,12 @@ vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
1671
1671
A [ _ vector_ ] ( #vector-types ) _ expression_ is written by enclosing zero or
1672
1672
more comma-separated expressions of uniform type in square brackets.
1673
1673
1674
+ In the ` [expr ',' ".." expr] ` form, the expression after the ` ".." `
1675
+ must be an expression form that can be evaluated at compile time, such
1676
+ as a [ literal] ( #literals ) or a [ constant] ( #constants ) .
1677
+
1678
+ <!-- - TODO: elaborate the actual subgrammar for constant expressions -->
1679
+
1674
1680
~~~~
1675
1681
[1, 2, 3, 4];
1676
1682
["a", "b", "c", "d"];
@@ -2156,6 +2162,19 @@ do f |j| {
2156
2162
}
2157
2163
~~~~
2158
2164
2165
+ In this example, both calls to the (binary) function ` k ` are equivalent:
2166
+
2167
+ ~~~~
2168
+ # fn k(x:int, f: &fn(int)) { }
2169
+ # fn l(i: int) { }
2170
+
2171
+ k(3, |j| l(j));
2172
+
2173
+ do k(3) |j| {
2174
+ l(j);
2175
+ }
2176
+ ~~~~
2177
+
2159
2178
2160
2179
### For expressions
2161
2180
@@ -2184,7 +2203,7 @@ and early boolean-valued returns from the `block` function,
2184
2203
such that the meaning of ` break ` and ` loop ` is preserved in a primitive loop
2185
2204
when rewritten as a ` for ` loop controlled by a higher order function.
2186
2205
2187
- An example a for loop:
2206
+ An example of a for loop over the contents of a vector :
2188
2207
2189
2208
~~~~
2190
2209
# type foo = int;
@@ -2198,6 +2217,14 @@ for v.each |e| {
2198
2217
}
2199
2218
~~~~
2200
2219
2220
+ An example of a for loop over a series of integers:
2221
+
2222
+ ~~~~
2223
+ # fn bar(b:uint) { }
2224
+ for uint::range(0, 256) |i| {
2225
+ bar(i);
2226
+ }
2227
+ ~~~~
2201
2228
2202
2229
### If expressions
2203
2230
@@ -2474,6 +2501,7 @@ fail_unless!(b != "world");
2474
2501
2475
2502
The vector type constructor represents a homogeneous array of values of a given type.
2476
2503
A vector has a fixed size.
2504
+ (Operations like ` vec::push ` operate solely on owned vectors.)
2477
2505
A vector type can be annotated with a _ definite_ size,
2478
2506
written with a trailing asterisk and integer literal, such as ` [int * 10] ` .
2479
2507
Such a definite-sized vector type is a first-class type, since its size is known statically.
@@ -2484,6 +2512,10 @@ such as `&[T]`, `@[T]` or `~[T]`.
2484
2512
The kind of a vector type depends on the kind of its element type,
2485
2513
as with other simple structural types.
2486
2514
2515
+ Expressions producing vectors of definite size cannot be evaluated in a
2516
+ context expecting a vector of indefinite size; one must copy the
2517
+ definite-sized vector contents into a distinct vector of indefinite size.
2518
+
2487
2519
An example of a vector type and its use:
2488
2520
2489
2521
~~~~
0 commit comments