From 90cd795b8bc22719e43183444d1963eda5161de6 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 19 Jan 2012 01:22:19 -0800 Subject: [PATCH] Update docs to reflect pattern syntax change --- doc/rust.texi | 10 ++-------- doc/tutorial/data.md | 12 +++++------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/doc/rust.texi b/doc/rust.texi index 0ed7748c1f9..68aaa414a69 100644 --- a/doc/rust.texi +++ b/doc/rust.texi @@ -2702,7 +2702,7 @@ arbitrary depth. A @dfn{declaration statement} is one that introduces a @emph{name} into the enclosing statement block. The declared name may denote a new slot or a new item. The scope of the name extends to the entire containing block, both -before and after the declaration. +before and after the declaration. Tag names may not be shadowed by variable names. @menu * Ref.Stmt.Decl.Item:: Statement declaring an item. @@ -3274,7 +3274,7 @@ alt x @{ cons(10, _) @{ process_ten(); @} - nil. @{ + nil @{ ret; @} _ @{ @@ -3283,12 +3283,6 @@ alt x @{ @} @end example -Note in the above example that @code{nil} is followed by a period. This is -required syntax for pattern matching a nullary tag variant, to distingush the -variant @code{nil} from a binding to variable @code{nil}. Without the period -the value of @code{x} would be bound to variable @code{nil} and the compiler -would issue an error about the final wildcard case being unreachable. - Records can also be pattern-matched and their fields bound to variables. When matching fields of a record, the fields being matched are specified first, then a placeholder (@code{_}) represents the remaining fields. diff --git a/doc/tutorial/data.md b/doc/tutorial/data.md index 600589d07b7..79a0cb85ac5 100644 --- a/doc/tutorial/data.md +++ b/doc/tutorial/data.md @@ -155,18 +155,16 @@ patterns, as in this definition of `area`: } } -For variants without arguments, you have to write `variantname.` (with -a dot at the end) to match them in a pattern. This to prevent -ambiguity between matching a variant name and binding a new variable. +Another example: # type point = {x: float, y: float}; # enum direction { north; east; south; west; } fn point_from_direction(dir: direction) -> point { alt dir { - north. { {x: 0f, y: 1f} } - east. { {x: 1f, y: 0f} } - south. { {x: 0f, y: -1f} } - west. { {x: -1f, y: 0f} } + north { {x: 0f, y: 1f} } + east { {x: 1f, y: 0f} } + south { {x: 0f, y: -1f} } + west { {x: -1f, y: 0f} } } }