diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 7c8e21464c4cc..c39c91d962296 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -142,7 +142,7 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path, tpt: ty_param_bounds_and_ty, sp: span) -> ty_param_substs_opt_and_ty { let ty_param_count = vec::len(*tpt.bounds); - let vars = vec::init_fn({|_i| next_ty_var(fcx)}, ty_param_count); + let vars = vec::init_fn(ty_param_count, {|_i| next_ty_var(fcx)}); let ty_substs_len = vec::len(pth.node.types); if ty_substs_len > 0u { let param_var_len = vec::len(vars); @@ -611,9 +611,9 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method, } else { let impl_fty = ty::mk_fn(tcx, impl_m.fty); // Add dummy substs for the parameters of the impl method - let substs = substs + vec::init_fn({|i| + let substs = substs + vec::init_fn(vec::len(*if_m.tps), {|i| ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0}) - }, vec::len(*if_m.tps)); + }); let if_fty = ty::substitute_type_params(tcx, substs, ty::mk_fn(tcx, if_m.fty)); alt ty::unify::unify(impl_fty, if_fty, ty::unify::precise, tcx) { @@ -2334,7 +2334,7 @@ fn next_ty_var(fcx: @fn_ctxt) -> ty::t { fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint) -> {vars: [ty::t], ty: ty::t} { - let vars = vec::init_fn({|_i| next_ty_var(fcx)}, count); + let vars = vec::init_fn(count, {|_i| next_ty_var(fcx)}); {vars: vars, ty: ty::substitute_type_params(fcx.ccx.tcx, vars, tp)} } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 33ff630e708b1..277eaafdcc2d6 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -88,7 +88,7 @@ Creates and initializes an immutable vector. Creates an immutable vector of size `n_elts` and initializes the elements to the value returned by the function `op`. */ -fn init_fn(op: init_op, n_elts: uint) -> [T] { +fn init_fn(n_elts: uint, op: init_op) -> [T] { let v = []; reserve(v, n_elts); let i: uint = 0u; @@ -105,7 +105,7 @@ Creates and initializes a mutable vector. Creates a mutable vector of size `n_elts` and initializes the elements to the value returned by the function `op`. */ -fn init_fn_mut(op: init_op, n_elts: uint) -> [mutable T] { +fn init_fn_mut(n_elts: uint, op: init_op) -> [mutable T] { let v = [mutable]; reserve(v, n_elts); let i: uint = 0u; @@ -365,13 +365,13 @@ Function: grow_fn Expands a vector in place, initializing the new elements to the result of a function -Function `init_fn` is called `n` times with the values [0..`n`) +Function `init_op` is called `n` times with the values [0..`n`) Parameters: v - The vector to grow n - The number of elements to add -init_fn - A function to call to retreive each appended element's value +init_op - A function to call to retreive each appended element's value */ fn grow_fn(&v: [T], n: uint, op: init_op) { reserve(v, next_power_of_two(len(v) + n)); @@ -1026,14 +1026,14 @@ mod tests { #[test] fn test_init_fn() { // Test on-stack init_fn. - let v = init_fn(square, 3u); + let v = init_fn(3u, square); assert (len(v) == 3u); assert (v[0] == 0u); assert (v[1] == 1u); assert (v[2] == 4u); // Test on-heap init_fn. - v = init_fn(square, 5u); + v = init_fn(5u, square); assert (len(v) == 5u); assert (v[0] == 0u); assert (v[1] == 1u); diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 30af05a9c4947..8296398c9e685 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -267,7 +267,7 @@ in the resulting vector has either value 0u or 1u. */ fn to_vec(v: t) -> [uint] { let sub = bind init_to_vec(v, _); - ret vec::init_fn::(sub, v.nbits); + ret vec::init_fn::(v.nbits, sub); } /* diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 697ce4035cdce..e4f73b2fe9d97 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -212,7 +212,7 @@ err(fail_) - On failure. Use to get an error message. fn getopts(args: [str], opts: [opt]) -> result { let n_opts = vec::len::(opts); fn f(_x: uint) -> [optval] { ret []; } - let vals = vec::init_fn_mut::<[optval]>(f, n_opts); + let vals = vec::init_fn_mut::<[optval]>(n_opts, f); let free: [str] = []; let l = vec::len(args); let i = 0u; diff --git a/src/test/bench/shootout-fannkuchredux.rs b/src/test/bench/shootout-fannkuchredux.rs index eb61182e40834..fce617b8d658f 100644 --- a/src/test/bench/shootout-fannkuchredux.rs +++ b/src/test/bench/shootout-fannkuchredux.rs @@ -7,7 +7,7 @@ fn fannkuch(n: int) -> int { fn perm1init(i: uint) -> int { ret i as int; } let perm = vec::init_elt_mut(0, n as uint); - let perm1 = vec::init_fn_mut(perm1init, n as uint); + let perm1 = vec::init_fn_mut(n as uint, perm1init); let count = vec::init_elt_mut(0, n as uint); let f = 0; let i = 0; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 01dcc5ed12593..ec3490036e3d8 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -31,7 +31,7 @@ tag grid_t { grid_ctor(grid); } fn read_grid(f: io::reader) -> grid_t { assert f.read_line() == "9,9"; /* assert first line is exactly "9,9" */ - let g = vec::init_fn({|_i| vec::init_elt_mut(0 as u8, 10u) }, 10u); + let g = vec::init_fn(10u, {|_i| vec::init_elt_mut(0 as u8, 10u) }); while !f.eof() { // FIXME: replace with unicode compliant call let comps = str::split(str::trim(f.read_line()), ',' as u8); @@ -130,7 +130,7 @@ fn write_grid(f: io::writer, g: grid_t) { fn main(args: [str]) { let grid = if vec::len(args) == 1u { // FIXME create sudoku inline since nested vec consts dont work yet - let g = vec::init_fn({|_i| vec::init_elt_mut(0 as u8, 10u) }, 10u); + let g = vec::init_fn(10u, {|_i| vec::init_elt_mut(0 as u8, 10u) }); g[0][1] = 4u8; g[0][3] = 6u8; g[0][7] = 3u8;