Skip to content

Commit 2e7ddee

Browse files
committed
tutorial: Simplify the first example. Misc
1 parent 3b89dcb commit 2e7ddee

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

doc/tutorial.md

+21-20
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,13 @@ paretheses, while their bodies *must* be wrapped in
204204
brackets. Single-statement, bracket-less bodies are not allowed.
205205

206206
~~~~
207-
# fn calibrate_universe() -> bool { false }
208-
# fn party_on() {}
209-
# fn panic() {}
207+
# fn recalibrate_universe() -> bool { true }
210208
fn main() {
211-
while calibrate_universe() {
212-
/* Ensure that basic math still operates is expected */
213-
if 2*20 > 30 {
214-
party_on(); // That's a relief
215-
} else {
216-
panic();
209+
/* A simple loop */
210+
loop {
211+
// A tricky calculation
212+
if recalibrate_universe() {
213+
return;
217214
}
218215
}
219216
}
@@ -438,10 +435,9 @@ The nil literal is written just like the type: `()`. The keywords
438435

439436
Character literals are written between single quotes, as in `'x'`. Just as in
440437
C, Rust understands a number of character escapes, using the backslash
441-
character, `\n`, `\r`, and `\t` being the most common.
442-
443-
String literals allow the same escape sequences. They are written
444-
between double quotes (`"hello"`). Rust strings may contain newlines.
438+
character, `\n`, `\r`, and `\t` being the most common. String literals,
439+
written between double quotes, allow the same escape sequences. Rust strings
440+
may contain newlines.
445441

446442
## Operators
447443

@@ -482,14 +478,19 @@ a syntax extension is being used, the names of all syntax extensions end with
482478
which is `fmt!`, a `sprintf`-style text formatter that is expanded at compile
483479
time.
484480

485-
~~~~
486-
io::println(fmt!("%s is %d", ~"the answer", 42));
487-
~~~~
488-
489481
`fmt!` supports most of the directives that [printf][pf] supports, but
490482
will give you a compile-time error when the types of the directives
491483
don't match the types of the arguments.
492484

485+
~~~~
486+
# let mystery_object = ();
487+
488+
io::println(fmt!("%s is %d", "the answer", 43));
489+
490+
// %? will conveniently print any type
491+
io::println(fmt!("what is this thing: %?", mystery_object));
492+
~~~~
493+
493494
[pf]: http://en.cppreference.com/w/cpp/io/c/fprintf
494495

495496
You can define your own syntax extensions with the macro system, which is out
@@ -505,11 +506,11 @@ compulsory, an optional `else` clause can be appended, and multiple
505506

506507
~~~~
507508
if false {
508-
io::println(~"that's odd");
509+
io::println("that's odd");
509510
} else if true {
510-
io::println(~"right");
511+
io::println("right");
511512
} else {
512-
io::println(~"neither true nor false");
513+
io::println("neither true nor false");
513514
}
514515
~~~~
515516

0 commit comments

Comments
 (0)