Skip to content

Commit 60e367a

Browse files
committed
---
yaml --- r: 31670 b: refs/heads/dist-snap c: ecaf9e3 h: refs/heads/master v: v3
1 parent d634528 commit 60e367a

File tree

360 files changed

+2939
-2916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+2939
-2916
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: d3a9bb1bd4a1d510bbaca2ab1121e4c85a239247
10+
refs/heads/dist-snap: ecaf9e39c9435fa2de4fe393c4b263be36eb2d99
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/doc/rust.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ import export use mod
209209
The keywords in [source files](#source-files) are the following strings:
210210

211211
~~~~~~~~ {.keyword}
212-
alt again assert
212+
again assert
213213
break
214214
check class const copy
215215
drop
216216
else enum export extern
217217
fail false fn for
218218
if impl import
219219
let log loop
220-
mod mut
220+
match mod mut
221221
pure
222222
return
223223
true trait type
@@ -956,7 +956,7 @@ An example of a predicate that uses an unchecked block:
956956
# import std::list::*;
957957
958958
fn pure_foldl<T, U: copy>(ls: list<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
959-
alt ls {
959+
match ls {
960960
nil => u,
961961
cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f))
962962
}
@@ -1156,7 +1156,7 @@ class file_descriptor {
11561156
let mut name: option<~str>;
11571157
}
11581158
fn get_name() -> ~str {
1159-
alt self.name {
1159+
match self.name {
11601160
none => fail ~"File has no name!",
11611161
some(n) => n
11621162
}
@@ -2171,21 +2171,21 @@ evaluated. If all `if` and `else if` conditions evaluate to `false`
21712171
then any `else` block is executed.
21722172

21732173

2174-
### Alternative expressions
2174+
### Match expressions
21752175

21762176
~~~~~~~~{.ebnf .gram}
2177-
alt_expr : "alt" expr '{' alt_arm [ '|' alt_arm ] * '}' ;
2177+
match_expr : "match" expr '{' match_arm [ '|' match_arm ] * '}' ;
21782178
2179-
alt_arm : alt_pat '=>' expr_or_blockish ;
2179+
match_arm : match_pat '=>' expr_or_blockish ;
21802180
2181-
alt_pat : pat [ "to" pat ] ? [ "if" expr ] ;
2181+
match_pat : pat [ "to" pat ] ? [ "if" expr ] ;
21822182
~~~~~~~~
21832183

21842184

2185-
An `alt` expression branches on a *pattern*. The exact form of matching that
2185+
A `match` expression branches on a *pattern*. The exact form of matching that
21862186
occurs depends on the pattern. Patterns consist of some combination of
21872187
literals, destructured enum constructors, records and tuples, variable binding
2188-
specifications, wildcards (`*`), and placeholders (`_`). An `alt` expression has a *head
2188+
specifications, wildcards (`*`), and placeholders (`_`). A `match` expression has a *head
21892189
expression*, which is the value to compare to the patterns. The type of the
21902190
patterns must equal the type of the head expression.
21912191

@@ -2198,7 +2198,7 @@ enum list<X> { nil, cons(X, @list<X>) }
21982198
21992199
let x: list<int> = cons(10, @cons(11, @nil));
22002200
2201-
alt x {
2201+
match x {
22022202
cons(_, @nil) => fail ~"singleton list",
22032203
cons(*) => return,
22042204
nil => fail ~"empty list"
@@ -2210,13 +2210,13 @@ tail value of `@nil`. The second pattern matches `any` list constructed with `co
22102210
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
22112211
`C` has exactly one argument, while the pattern `C(*)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
22122212

2213-
To execute an `alt` expression, first the head expression is evaluated, then
2213+
To execute an `match` expression, first the head expression is evaluated, then
22142214
its value is sequentially compared to the patterns in the arms until a match
22152215
is found. The first arm with a matching pattern is chosen as the branch target
2216-
of the `alt`, any variables bound by the pattern are assigned to local
2216+
of the `match`, any variables bound by the pattern are assigned to local
22172217
variables in the arm's block, and control enters the block.
22182218

2219-
An example of an `alt` expression:
2219+
An example of an `match` expression:
22202220

22212221

22222222
~~~~
@@ -2227,7 +2227,7 @@ enum list<X> { nil, cons(X, @list<X>) }
22272227
22282228
let x: list<int> = cons(10, @cons(11, @nil));
22292229
2230-
alt x {
2230+
match x {
22312231
cons(a, @cons(b, _)) => {
22322232
process_pair(a,b);
22332233
}
@@ -2264,7 +2264,7 @@ fn main() {
22642264
}
22652265
};
22662266
2267-
alt r {
2267+
match r {
22682268
{options: {choose: true, _}, _} => {
22692269
choose_player(r)
22702270
}
@@ -2278,20 +2278,20 @@ fn main() {
22782278
}
22792279
~~~~
22802280

2281-
Multiple alternative patterns may be joined with the `|` operator. A
2281+
Multiple match patterns may be joined with the `|` operator. A
22822282
range of values may be specified with `to`. For example:
22832283

22842284
~~~~
22852285
# let x = 2;
22862286
2287-
let message = alt x {
2287+
let message = match x {
22882288
0 | 1 => ~"not many",
22892289
2 to 9 => ~"a few",
22902290
_ => ~"lots"
22912291
};
22922292
~~~~
22932293

2294-
Finally, alt patterns can accept *pattern guards* to further refine the
2294+
Finally, match patterns can accept *pattern guards* to further refine the
22952295
criteria for matching a case. Pattern guards appear after the pattern and
22962296
consist of a bool-typed expression following the `if` keyword. A pattern
22972297
guard may refer to the variables bound within the pattern they follow.
@@ -2301,7 +2301,7 @@ guard may refer to the variables bound within the pattern they follow.
23012301
# fn process_digit(i: int) { }
23022302
# fn process_other(i: int) { }
23032303
2304-
let message = alt maybe_digit {
2304+
let message = match maybe_digit {
23052305
some(x) if x < 10 => process_digit(x),
23062306
some(x) => process_other(x),
23072307
none => fail

branches/dist-snap/doc/tutorial.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn main() {
116116
let pick = || (~[rock, paper, scissors])[rng.gen_uint() % 3];
117117
118118
// Pick two gestures and decide the result
119-
alt (pick(), pick()) {
119+
match (pick(), pick()) {
120120
(rock, scissors) | (paper, rock) | (scissors, paper) => copy player1,
121121
(scissors, rock) | (rock, paper) | (paper, scissors) => copy player2,
122122
_ => ~"tie"
@@ -707,14 +707,14 @@ have type `int`, because control doesn't reach the end of that arm
707707

708708
## Pattern matching
709709

710-
Rust's `alt` construct is a generalized, cleaned-up version of C's
710+
Rust's `match` construct is a generalized, cleaned-up version of C's
711711
`switch` construct. You provide it with a value and a number of arms,
712712
each labelled with a pattern, and it will execute the arm that matches
713713
the value.
714714

715715
~~~~
716716
# let my_number = 1;
717-
alt my_number {
717+
match my_number {
718718
0 => io::println(~"zero"),
719719
1 | 2 => io::println(~"one or two"),
720720
3 to 10 => io::println(~"three to ten"),
@@ -732,14 +732,14 @@ valid patterns, and will match only their own value. The pipe operator
732732
of numeric literal patterns can be expressed with `to`. The underscore
733733
(`_`) is a wildcard pattern that matches everything.
734734

735-
The patterns in an alt arm are followed by a fat arrow, `=>`, then an
735+
The patterns in an match arm are followed by a fat arrow, `=>`, then an
736736
expression to evaluate. Each case is separated by commas. It's often
737737
convenient to use a block expression for a case, in which case the
738738
commas are optional.
739739

740740
~~~
741741
# let my_number = 1;
742-
alt my_number {
742+
match my_number {
743743
0 => {
744744
io::println(~"zero")
745745
}
@@ -750,9 +750,9 @@ alt my_number {
750750
~~~
751751

752752
If the arm with the wildcard pattern was left off in the above
753-
example, the typechecker would reject it at compile time. `alt`
753+
example, the typechecker would reject it at compile time. `match`
754754
constructs must be exhaustive: they must have an arm covering every
755-
possible case. (You may use the `alt check` construct to write a
755+
possible case. (You may use the `match check` construct to write a
756756
non-exhaustive match, but it's highly undesirable to do so. You may
757757
reason that the missing cases will never occur, but the typechecker
758758
provides you with no assurance that your reasoning is correct.)
@@ -763,7 +763,7 @@ that `(float, float)` is a tuple of two floats:
763763

764764
~~~~
765765
fn angle(vec: (float, float)) -> float {
766-
alt vec {
766+
match vec {
767767
(0f, y) if y < 0f => 1.5 * float::consts::pi,
768768
(0f, y) => 0.5 * float::consts::pi,
769769
(x, y) => float::atan(y / x)
@@ -777,7 +777,7 @@ y)` matches any tuple whose first element is zero, and binds `y` to
777777
the second element. `(x, y)` matches any tuple, and binds both
778778
elements to a variable.
779779

780-
Any `alt` arm can have a guard clause (written `if EXPR`), which is
780+
Any `match` arm can have a guard clause (written `if EXPR`), which is
781781
an expression of type `bool` that determines, after the pattern is
782782
found to match, whether the arm is taken or not. The variables bound
783783
by the pattern are available in this guard expression.
@@ -851,7 +851,7 @@ task failure:
851851

852852
* Accessing an out-of-bounds element of a vector.
853853

854-
* Having no clauses match when evaluating an `alt check` expression.
854+
* Having no clauses match when evaluating an `match check` expression.
855855

856856
* An assertion failure.
857857

@@ -1044,14 +1044,14 @@ not an actual new type.)
10441044

10451045
## Record patterns
10461046

1047-
Records can be destructured in `alt` patterns. The basic syntax is
1047+
Records can be destructured in `match` patterns. The basic syntax is
10481048
`{fieldname: pattern, ...}`, but the pattern for a field can be
10491049
omitted as a shorthand for simply binding the variable with the same
10501050
name as the field.
10511051

10521052
~~~~
10531053
# let mypoint = {x: 0f, y: 0f};
1054-
alt mypoint {
1054+
match mypoint {
10551055
{x: 0f, y: y_name} => { /* Provide sub-patterns for fields */ }
10561056
{x, y} => { /* Simply bind the fields */ }
10571057
}
@@ -1157,7 +1157,7 @@ patterns, as in this definition of `area`:
11571157
# type point = {x: float, y: float};
11581158
# enum shape { circle(point, float), rectangle(point, point) }
11591159
fn area(sh: shape) -> float {
1160-
alt sh {
1160+
match sh {
11611161
circle(_, size) => float::consts::pi * size * size,
11621162
rectangle({x, y}, {x: x2, y: y2}) => (x2 - x) * (y2 - y)
11631163
}
@@ -1170,7 +1170,7 @@ Another example, matching nullary enum variants:
11701170
# type point = {x: float, y: float};
11711171
# enum direction { north, east, south, west }
11721172
fn point_from_direction(dir: direction) -> point {
1173-
alt dir {
1173+
match dir {
11741174
north => {x: 0f, y: 1f},
11751175
east => {x: 1f, y: 0f},
11761176
south => {x: 0f, y: -1f},
@@ -1188,7 +1188,7 @@ nil, `()`, as the empty tuple if you like).
11881188

11891189
~~~~
11901190
let mytup: (int, int, float) = (10, 20, 30.0);
1191-
alt mytup {
1191+
match mytup {
11921192
(a, b, c) => log(info, a + b + (c as int))
11931193
}
11941194
~~~~
@@ -1922,15 +1922,15 @@ gets access to them.
19221922
## Other uses of safe references
19231923

19241924
Safe references are not only used for argument passing. When you
1925-
destructure on a value in an `alt` expression, or loop over a vector
1925+
destructure on a value in a `match` expression, or loop over a vector
19261926
with `for`, variables bound to the inside of the given data structure
19271927
will use safe references, not copies. This means such references are
19281928
very cheap, but you'll occasionally have to copy them to ensure
19291929
safety.
19301930

19311931
~~~~
19321932
let mut my_rec = {a: 4, b: ~[1, 2, 3]};
1933-
alt my_rec {
1933+
match my_rec {
19341934
{a, b} => {
19351935
log(info, b); // This is okay
19361936
my_rec = {a: a + 1, b: b + ~[a]};

0 commit comments

Comments
 (0)