diff options
| author | bors <bors@rust-lang.org> | 2013-08-01 22:10:45 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-01 22:10:45 -0700 |
| commit | bbcce8d95c582d3f918fe4e978d6a715efd991e9 (patch) | |
| tree | 6c0a714130897160fc6ef8a3d17671aed2bc8b90 /doc | |
| parent | ecefeb03ccecdcb306e5cc3c76b04670073a82fa (diff) | |
| parent | 234acad404535868ecd7f5b48c3e120c4ea559c9 (diff) | |
| download | rust-bbcce8d95c582d3f918fe4e978d6a715efd991e9.tar.gz rust-bbcce8d95c582d3f918fe4e978d6a715efd991e9.zip | |
auto merge of #8216 : thestinger/rust/range, r=huonw
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/rust.md | 3 | ||||
| -rw-r--r-- | doc/tutorial-tasks.md | 12 |
2 files changed, 5 insertions, 10 deletions
diff --git a/doc/rust.md b/doc/rust.md index 51b2786746a..ea4d7ec3fe9 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -2386,9 +2386,8 @@ foreach e in v.iter() { An example of a for loop over a series of integers: ~~~~ -# use std::uint; # fn bar(b:uint) { } -for uint::range(0, 256) |i| { +foreach i in range(0u, 256) { bar(i); } ~~~~ diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index 08989be871b..4528f3f9e15 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -120,9 +120,8 @@ should interleave the output in vaguely random order. ~~~ # use std::io::print; # use std::task::spawn; -# use std::int; -for int::range(0, 20) |child_task_number| { +foreach child_task_number in range(0, 20) { do spawn { print(fmt!("I am child number %d\n", child_task_number)); } @@ -237,12 +236,11 @@ Instead we can use a `SharedChan`, a type that allows a single ~~~ # use std::task::spawn; # use std::comm::{stream, SharedChan}; -# use std::uint; let (port, chan) = stream(); let chan = SharedChan::new(chan); -for uint::range(0, 3) |init_val| { +foreach init_val in range(0u, 3) { // Create a new channel handle to distribute to the child task let child_chan = chan.clone(); do spawn { @@ -314,10 +312,9 @@ Here is another example showing how futures allow you to background computations be distributed on the available cores. ~~~ # use std::vec; -# use std::uint; fn partial_sum(start: uint) -> f64 { let mut local_sum = 0f64; - for uint::range(start*100000, (start+1)*100000) |num| { + foreach num in range(start*100000, (start+1)*100000) { local_sum += (num as f64 + 1.0).pow(&-2.0); } local_sum @@ -349,7 +346,6 @@ Here is a small example showing how to use Arcs. We wish to run concurrently sev a single large vector of floats. Each task needs the full vector to perform its duty. ~~~ # use std::vec; -# use std::uint; # use std::rand; use extra::arc::Arc; @@ -363,7 +359,7 @@ fn main() { let numbers_arc = Arc::new(numbers); - for uint::range(1,10) |num| { + foreach num in range(1u, 10) { let (port, chan) = stream(); chan.send(numbers_arc.clone()); |
