From aa01876c95a3f50ef6129f1501d97c7a6bb0e856 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 1 Nov 2011 14:38:55 +0100 Subject: Flesh out the module section of the tutorial --- doc/tutorial/syntax.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'doc/tutorial/syntax.md') diff --git a/doc/tutorial/syntax.md b/doc/tutorial/syntax.md index a40c9822152..8c6a54f50d4 100644 --- a/doc/tutorial/syntax.md +++ b/doc/tutorial/syntax.md @@ -86,6 +86,27 @@ The double-colon (`::`) is used as a module separator, so `std::io::println` means 'the thing named `println` in the module named `io` in the module named `std`'. +Rust will normally emit warning about unused variables. These can be +suppressed by using a variable name that starts with an underscore. + + fn this_warns(x: int) {} + fn this_doesnt(_x: int) {} + +## Variable declaration + +The `let` keyword, as we've seen, introduces a local variable. Global +constants can be defined with `const`: + + import std; + const repeat: uint = 5u; + fn main() { + let count = 0u; + while count < repeat { + std::io::println("Hi!"); + count += 1u; + } + } + ## Types The `-> bool` in the last example is the way a function's return type @@ -256,3 +277,7 @@ exists, convert the result of the expression to the given type. let x: float = 4.0; let y: uint = x as uint; assert y == 4u; + +## Attributes + +FIXME Briefly introduce attributes -- cgit 1.4.1-3-g733a5