about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/bitv.rs12
-rw-r--r--src/libstd/getopts.rs4
-rw-r--r--src/libstd/sha1.rs10
-rw-r--r--src/libstd/sort.rs6
-rw-r--r--src/libstd/term.rs2
-rw-r--r--src/libstd/test.rs6
6 files changed, 25 insertions, 15 deletions
diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs
index 37df940f6fb..5d100fa0623 100644
--- a/src/libstd/bitv.rs
+++ b/src/libstd/bitv.rs
@@ -173,14 +173,14 @@ fn set(v: bitv, i: uint, x: bool) {
 
 #[doc = "Returns true if all bits are 1"]
 fn is_true(v: bitv) -> bool {
-    for i: uint in to_vec(v) { if i != 1u { ret false; } }
+    for each(v) {|i| if !i { ret false; } }
     ret true;
 }
 
 
 #[doc = "Returns true if all bits are 0"]
 fn is_false(v: bitv) -> bool {
-    for i: uint in to_vec(v) { if i == 1u { ret false; } }
+    for each(v) {|i| if i { ret false; } }
     ret true;
 }
 
@@ -198,6 +198,12 @@ fn to_vec(v: bitv) -> [uint] {
     ret vec::from_fn::<uint>(v.nbits, sub);
 }
 
+fn each(v: bitv, f: fn(bool) -> bool) {
+    let mut i = 0u;
+    while i < v.nbits {
+        if !f(get(v, i)) { break; }
+    }
+}
 
 #[doc = "
 Converts the bitvector to a string.
@@ -207,7 +213,7 @@ is either '0' or '1'.
 "]
 fn to_str(v: bitv) -> str {
     let mut rs = "";
-    for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } }
+    for each(v) {|i| if i { rs += "1"; } else { rs += "0"; } }
     ret rs;
 }
 
diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs
index 3d921fb4d9d..beec5638b84 100644
--- a/src/libstd/getopts.rs
+++ b/src/libstd/getopts.rs
@@ -208,7 +208,7 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
                 }
             }
             let mut name_pos = 0u;
-            for nm: name in names {
+            for vec::each(names) {|nm|
                 name_pos += 1u;
                 let optid = alt find_opt(opts, nm) {
                   some(id) { id }
@@ -290,7 +290,7 @@ Used when an option accepts multiple values.
 "]
 fn opt_strs(m: match, nm: str) -> [str] {
     let mut acc: [str] = [];
-    for v: optval in opt_vals(m, nm) {
+    for vec::each(opt_vals(m, nm)) {|v|
         alt v { val(s) { acc += [s]; } _ { } }
     }
     ret acc;
diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs
index 8e5f0cb122a..78a4aa91045 100644
--- a/src/libstd/sha1.rs
+++ b/src/libstd/sha1.rs
@@ -63,7 +63,7 @@ fn sha1() -> sha1 {
     fn add_input(st: sha1state, msg: [u8]) {
         // FIXME: Should be typestate precondition
         assert (!st.computed);
-        for element: u8 in msg {
+        for vec::each(msg) {|element|
             st.msg_block[st.msg_block_idx] = element;
             st.msg_block_idx += 1u;
             st.len_low += 8u32;
@@ -161,7 +161,7 @@ fn sha1() -> sha1 {
     fn mk_result(st: sha1state) -> [u8] {
         if !st.computed { pad_msg(st); st.computed = true; }
         let mut rs: [u8] = [];
-        for hpart: u32 in st.h {
+        for vec::each(st.h) {|hpart|
             let a = (hpart >> 24u32 & 0xFFu32) as u8;
             let b = (hpart >> 16u32 & 0xFFu32) as u8;
             let c = (hpart >> 8u32 & 0xFFu32) as u8;
@@ -238,7 +238,7 @@ fn sha1() -> sha1 {
         fn result_str() -> str {
             let r = mk_result(self);
             let mut s = "";
-            for b: u8 in r { s += uint::to_str(b as uint, 16u); }
+            for vec::each(r) {|b| s += uint::to_str(b as uint, 16u); }
             ret s;
         }
     }
@@ -327,7 +327,7 @@ mod tests {
         // Test that it works when accepting the message all at once
 
         let sh = sha1::sha1();
-        for t: test in tests {
+        for vec::each(tests) {|t|
             sh.input_str(t.input);
             let out = sh.result();
             check_vec_eq(t.output, out);
@@ -336,7 +336,7 @@ mod tests {
 
 
         // Test that it works when accepting the message in pieces
-        for t: test in tests {
+        for vec::each(tests) {|t|
             let len = str::len(t.input);
             let mut left = len;
             while left > 0u {
diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs
index 8385158e93a..e9228eae1bc 100644
--- a/src/libstd/sort.rs
+++ b/src/libstd/sort.rs
@@ -254,7 +254,11 @@ mod test_qsort {
         let immut_names = vec::from_mut(names);
 
         let pairs = vec::zip(expected, immut_names);
-        for (a, b) in pairs { #debug("%d %d", a, b); assert (a == b); }
+        for vec::each(pairs) {|p|
+            let (a, b) = p;
+            #debug("%d %d", a, b);
+            assert (a == b);
+        }
     }
 }
 
diff --git a/src/libstd/term.rs b/src/libstd/term.rs
index c18cc2a625d..3bbde56693a 100644
--- a/src/libstd/term.rs
+++ b/src/libstd/term.rs
@@ -37,7 +37,7 @@ fn color_supported() -> bool {
                            "screen-bce", "xterm-256color"];
     ret alt os::getenv("TERM") {
           option::some(env) {
-            for term: str in supported_terms {
+            for vec::each(supported_terms) {|term|
                 if str::eq(term, env) { ret true; }
             }
             false
diff --git a/src/libstd/test.rs b/src/libstd/test.rs
index 5847dea1e4e..d2138dc14d6 100644
--- a/src/libstd/test.rs
+++ b/src/libstd/test.rs
@@ -183,7 +183,7 @@ fn print_failures(st: console_test_state) {
     st.out.write_line("\nfailures:");
     let failures = vec::map(copy st.failures) {|test| test.name};
     let failures = sort::merge_sort(str::le, failures);
-    for name in failures {
+    for vec::each(failures) {|name|
         st.out.write_line(#fmt["    %s", name]);
     }
 }
@@ -492,7 +492,7 @@ mod tests {
         {
         let testfn = fn~() { };
         let mut tests = [];
-        for name: str in names {
+        for vec::each(names) {|name|
             let test = {name: name, fn: testfn, ignore: false,
                         should_fail: false};
             tests += [test];
@@ -510,7 +510,7 @@ mod tests {
 
     let pairs = vec::zip(expected, filtered);
 
-    for (a, b) in pairs { assert (a == b.name); }
+    for vec::each(pairs) {|p| let (a, b) = p; assert (a == b.name); }
 }
 }