fix #1352: change param order on vec::init_fn (and vec::init_fn_mut), putting block in final position.

This commit is contained in:
Graham Fawcett 2012-01-18 15:18:26 -05:00 committed by Brian Anderson
parent 818b646950
commit 35d12be2ce
6 changed files with 15 additions and 15 deletions

View File

@ -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)}
}

View File

@ -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<T>(op: init_op<T>, n_elts: uint) -> [T] {
fn init_fn<T>(n_elts: uint, op: init_op<T>) -> [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<T>(op: init_op<T>, n_elts: uint) -> [mutable T] {
fn init_fn_mut<T>(n_elts: uint, op: init_op<T>) -> [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<T>(&v: [T], n: uint, op: init_op<T>) {
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);

View File

@ -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::<uint>(sub, v.nbits);
ret vec::init_fn::<uint>(v.nbits, sub);
}
/*

View File

@ -212,7 +212,7 @@ err(fail_) - On failure. Use <fail_str> to get an error message.
fn getopts(args: [str], opts: [opt]) -> result {
let n_opts = vec::len::<opt>(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;

View File

@ -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;

View File

@ -31,7 +31,7 @@ enum 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;