De-mode vec::each() and many of the str iteration routines
Note that the method foo.each() is not de-moded, nor the other vec routines.
This commit is contained in:
parent
62b7f4d800
commit
9cf271fe96
81 changed files with 556 additions and 750 deletions
|
|
@ -75,9 +75,12 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
|
|||
};
|
||||
|
||||
do vec::each(edges) |e| {
|
||||
let (i, j) = e;
|
||||
map::set_add(graph[i], j);
|
||||
map::set_add(graph[j], i);
|
||||
match *e {
|
||||
(i, j) => {
|
||||
map::set_add(graph[i], j);
|
||||
map::set_add(graph[j], i);
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,10 @@ fn run(args: &[~str]) {
|
|||
server(from_parent, to_parent);
|
||||
}
|
||||
|
||||
vec::iter(worker_results, |r| { future::get(&r); } );
|
||||
for vec::each(worker_results) |r| {
|
||||
future::get(r);
|
||||
}
|
||||
|
||||
//error!("sending stop message");
|
||||
to_child.send(stop);
|
||||
move_out!(to_child);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,10 @@ fn run(args: &[~str]) {
|
|||
server(from_parent, to_parent);
|
||||
}
|
||||
|
||||
vec::iter(worker_results, |r| { future::get(&r); } );
|
||||
for vec::each(worker_results) |r| {
|
||||
future::get(r);
|
||||
}
|
||||
|
||||
//error!("sending stop message");
|
||||
to_child.send(stop);
|
||||
move_out!(to_child);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ fn run(args: ~[~str]) {
|
|||
}
|
||||
};
|
||||
}
|
||||
vec::iter(worker_results, |r| { future::get(&r); } );
|
||||
for vec::each(worker_results) |r| {
|
||||
future::get(r);
|
||||
}
|
||||
comm::send(to_child, stop);
|
||||
let result = comm::recv(from_child);
|
||||
let end = std::time::precise_time_s();
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ fn print_complements() {
|
|||
let all = ~[Blue, Red, Yellow];
|
||||
for vec::each(all) |aa| {
|
||||
for vec::each(all) |bb| {
|
||||
io::println(show_color(aa) + ~" + " + show_color(bb) +
|
||||
~" -> " + show_color(transform(aa,bb)));
|
||||
io::println(show_color(*aa) + ~" + " + show_color(*bb) +
|
||||
~" -> " + show_color(transform(*aa, *bb)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
|||
|
||||
// print each creature's stats
|
||||
for vec::each(report) |rep| {
|
||||
io::println(rep);
|
||||
io::println(*rep);
|
||||
}
|
||||
|
||||
// print the total number of creatures met
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ fn calc(children: uint, parent_ch: comm::Chan<msg>) {
|
|||
|
||||
match comm::recv(port) {
|
||||
start => {
|
||||
do vec::iter (child_chs) |child_ch| {
|
||||
comm::send(child_ch, start);
|
||||
}
|
||||
for vec::each(child_chs) |child_ch| {
|
||||
comm::send(*child_ch, start);
|
||||
}
|
||||
}
|
||||
_ => fail ~"task-perf-one-million failed (port not in start state)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn want_slice(v: &[int]) -> int {
|
||||
let mut sum = 0;
|
||||
for vec::each(v) |i| { sum += i; }
|
||||
for vec::each(v) |i| { sum += *i; }
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn main() {
|
||||
do vec::iter(fail) |i| {
|
||||
for vec::each(fail) |i| {
|
||||
log (debug, i * 2);
|
||||
//~^ ERROR the type of this value must be known
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
fn main() {
|
||||
let a: ~[int] = ~[];
|
||||
vec::each(a, fn@(_x: int) -> bool { //~ ERROR not all control paths return a value
|
||||
vec::each(a, fn@(_x: &int) -> bool {
|
||||
//~^ ERROR not all control paths return a value
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ fn concat<T: Copy>(v: ~[const ~[const T]]) -> ~[T] {
|
|||
let mut r = ~[];
|
||||
|
||||
// Earlier versions of our type checker accepted this:
|
||||
vec::iter(v, |&&inner: ~[T]| {
|
||||
vec::each(v, |inner: &~[T]| {
|
||||
//~^ ERROR values differ in mutability
|
||||
r += inner;
|
||||
r += *inner; true
|
||||
});
|
||||
|
||||
return r;
|
||||
|
|
|
|||
|
|
@ -2,21 +2,23 @@
|
|||
// making method calls, but only if there aren't any matches without
|
||||
// it.
|
||||
|
||||
#[legacy_modes];
|
||||
|
||||
trait iterable<A> {
|
||||
fn iterate(blk: fn(A) -> bool);
|
||||
fn iterate(blk: fn(x: &A) -> bool);
|
||||
}
|
||||
|
||||
impl<A> &[A]: iterable<A> {
|
||||
fn iterate(f: fn(A) -> bool) {
|
||||
vec::each(self, f);
|
||||
fn iterate(f: fn(x: &A) -> bool) {
|
||||
for vec::each(self) |e| {
|
||||
if !f(e) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> ~[A]: iterable<A> {
|
||||
fn iterate(f: fn(A) -> bool) {
|
||||
vec::each(self, f);
|
||||
fn iterate(f: fn(x: &A) -> bool) {
|
||||
for vec::each(self) |e| {
|
||||
if !f(e) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ fn length<A, T: iterable<A>>(x: T) -> uint {
|
|||
fn main() {
|
||||
let x = ~[0,1,2,3];
|
||||
// Call a method
|
||||
for x.iterate() |y| { assert x[y] == y; }
|
||||
for x.iterate() |y| { assert x[*y] == *y; }
|
||||
// Call a parameterized function
|
||||
assert length(x) == vec::len(x);
|
||||
// Call a parameterized function, with type arguments that require
|
||||
|
|
@ -39,7 +41,7 @@ fn main() {
|
|||
// Now try it with a type that *needs* to be borrowed
|
||||
let z = [0,1,2,3]/_;
|
||||
// Call a method
|
||||
for z.iterate() |y| { assert z[y] == y; }
|
||||
for z.iterate() |y| { assert z[*y] == *y; }
|
||||
// Call a parameterized function
|
||||
assert length::<int, &[int]>(z) == vec::len(z);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
fn main() {
|
||||
let mut sum = 0;
|
||||
for vec::each(~[1, 2, 3, 4, 5]) |x| { sum += x; }
|
||||
for vec::each(~[1, 2, 3, 4, 5]) |x| {
|
||||
sum += *x;
|
||||
}
|
||||
assert (sum == 15);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ fn main() {
|
|||
let v = ~[-1f, 0f, 1f, 2f, 3f];
|
||||
|
||||
// Statement form does not require parentheses:
|
||||
do vec::iter(v) |i| {
|
||||
log(info, i);
|
||||
for vec::each(v) |i| {
|
||||
log(info, *i);
|
||||
}
|
||||
|
||||
// Usable at all:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn want_slice(v: &[int]) -> int {
|
||||
let mut sum = 0;
|
||||
for vec::each(v) |i| { sum += i; }
|
||||
for vec::each(v) |i| { sum += *i; }
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
loop { i += 1; if i == 20 { break; } }
|
||||
assert (i == 20);
|
||||
for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
|
||||
if x == 3 { break; } assert (x <= 3);
|
||||
if *x == 3 { break; } assert (*x <= 3);
|
||||
}
|
||||
i = 0;
|
||||
while i < 10 { i += 1; if i % 2 == 0 { loop; } assert (i % 2 != 0); }
|
||||
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
if i >= 10 { break; }
|
||||
}
|
||||
for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
|
||||
if x % 2 == 0 { loop; }
|
||||
assert (x % 2 != 0);
|
||||
if *x % 2 == 0 { loop; }
|
||||
assert (*x % 2 != 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ trait sum {
|
|||
impl &[int]: sum {
|
||||
fn sum() -> int {
|
||||
let mut sum = 0;
|
||||
for vec::each(self) |e| { sum += e; }
|
||||
for vec::each(self) |e| { sum += *e; }
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue