You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A [_vector_](#vector-types)_expression_ is written by enclosing zero or
@@ -1558,6 +1574,7 @@ When no mutability is specified, the vector is immutable.
1558
1574
~~~~
1559
1575
[1, 2, 3, 4];
1560
1576
["a", "b", "c", "d"];
1577
+
[0, ..128]; // vector with 128 zeros
1561
1578
[mut 0u8, 0u8, 0u8, 0u8];
1562
1579
~~~~
1563
1580
@@ -1889,7 +1906,7 @@ let x: int = add(1, 2);
1889
1906
1890
1907
~~~~~~~~{.abnf .gram}
1891
1908
ident_list : [ ident [ ',' ident ]* ] ? ;
1892
-
lambda_expr : '|' ident_list '| expr ;
1909
+
lambda_expr : '|' ident_list '|' expr ;
1893
1910
~~~~~~~~
1894
1911
1895
1912
A _lambda expression_ (a.k.a. "anonymous function expression") defines a function and denotes it as a value,
@@ -2169,17 +2186,6 @@ Records and structures can also be pattern-matched and their fields bound to var
2169
2186
When matching fields of a record,
2170
2187
the fields being matched are specified first,
2171
2188
then a placeholder (`_`) represents the remaining fields.
2172
-
2173
-
A pattern that's just a variable binding,
2174
-
like `Nil` in the previous answer,
2175
-
could either refer to an enum variant that's in scope,
2176
-
or bind a new variable.
2177
-
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2178
-
For example, wherever ```List``` is in scope,
2179
-
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2180
-
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2181
-
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2182
-
and local variables with lower-case letters.
2183
2189
2184
2190
~~~~
2185
2191
# type options = {choose: bool, size: ~str};
@@ -2212,6 +2218,22 @@ fn main() {
2212
2218
}
2213
2219
~~~~
2214
2220
2221
+
Patterns that bind variables default to binding to a copy of the matched value. This can be made
2222
+
explicit using the ```copy``` keyword, changed to bind to a borrowed pointer by using the ```ref```
2223
+
keyword, or to a mutable borrowed pointer using ```ref mut```, or the value can be moved into
2224
+
the new binding using ```move```.
2225
+
2226
+
A pattern that's just an identifier,
2227
+
like `Nil` in the previous answer,
2228
+
could either refer to an enum variant that's in scope,
2229
+
or bind a new variable.
2230
+
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2231
+
For example, wherever ```List``` is in scope,
2232
+
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2233
+
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2234
+
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2235
+
and local variables with lower-case letters.
2236
+
2215
2237
Multiple match patterns may be joined with the `|` operator. A
2216
2238
range of values may be specified with `..`. For example:
0 commit comments