@@ -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,
712712each labelled with a pattern, and it will execute the arm that matches
713713the 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
732732of 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
736736expression to evaluate. Each case is separated by commas. It's often
737737convenient to use a block expression for a case, in which case the
738738commas 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
752752If 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 `
754754constructs 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
756756non-exhaustive match, but it's highly undesirable to do so. You may
757757reason that the missing cases will never occur, but the typechecker
758758provides you with no assurance that your reasoning is correct.)
@@ -763,7 +763,7 @@ that `(float, float)` is a tuple of two floats:
763763
764764~~~~
765765fn 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
777777the second element. ` (x, y) ` matches any tuple, and binds both
778778elements 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
781781an expression of type ` bool ` that determines, after the pattern is
782782found to match, whether the arm is taken or not. The variables bound
783783by 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
10491049omitted as a shorthand for simply binding the variable with the same
10501050name 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) }
11591159fn 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 }
11721172fn 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~~~~
11901190let 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
19241924Safe 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
19261926with ` for ` , variables bound to the inside of the given data structure
19271927will use safe references, not copies. This means such references are
19281928very cheap, but you'll occasionally have to copy them to ensure
19291929safety.
19301930
19311931~~~~
19321932let 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