File tree 2 files changed +7
-15
lines changed
2 files changed +7
-15
lines changed Original file line number Diff line number Diff line change @@ -2702,7 +2702,7 @@ arbitrary depth.
2702
2702
A @dfn {declaration statement } is one that introduces a @emph {name } into the
2703
2703
enclosing statement block. The declared name may denote a new slot or a new
2704
2704
item. The scope of the name extends to the entire containing block, both
2705
- before and after the declaration.
2705
+ before and after the declaration. Tag names may not be shadowed by variable names.
2706
2706
2707
2707
@menu
2708
2708
* Ref.Stmt.Decl.Item :: Statement declaring an item.
@@ -3274,7 +3274,7 @@ alt x @{
3274
3274
cons(10, _) @{
3275
3275
process_ten();
3276
3276
@}
3277
- nil. @{
3277
+ nil @{
3278
3278
ret;
3279
3279
@}
3280
3280
_ @{
@@ -3283,12 +3283,6 @@ alt x @{
3283
3283
@}
3284
3284
@end example
3285
3285
3286
- Note in the above example that @code {nil } is followed by a period. This is
3287
- required syntax for pattern matching a nullary tag variant, to distingush the
3288
- variant @code {nil } from a binding to variable @code {nil }. Without the period
3289
- the value of @code {x } would be bound to variable @code {nil } and the compiler
3290
- would issue an error about the final wildcard case being unreachable.
3291
-
3292
3286
Records can also be pattern-matched and their fields bound to variables.
3293
3287
When matching fields of a record, the fields being matched are specified
3294
3288
first, then a placeholder (@code {_ }) represents the remaining fields.
Original file line number Diff line number Diff line change @@ -155,18 +155,16 @@ patterns, as in this definition of `area`:
155
155
}
156
156
}
157
157
158
- For variants without arguments, you have to write ` variantname. ` (with
159
- a dot at the end) to match them in a pattern. This to prevent
160
- ambiguity between matching a variant name and binding a new variable.
158
+ Another example:
161
159
162
160
# type point = {x: float, y: float};
163
161
# enum direction { north; east; south; west; }
164
162
fn point_from_direction(dir: direction) -> point {
165
163
alt dir {
166
- north. { {x: 0f, y: 1f} }
167
- east. { {x: 1f, y: 0f} }
168
- south. { {x: 0f, y: -1f} }
169
- west. { {x: -1f, y: 0f} }
164
+ north { {x: 0f, y: 1f} }
165
+ east { {x: 1f, y: 0f} }
166
+ south { {x: 0f, y: -1f} }
167
+ west { {x: -1f, y: 0f} }
170
168
}
171
169
}
172
170
You can’t perform that action at this time.
0 commit comments