reorder args to the various vec, option fns so blk comes last
This commit is contained in:
parent
0a3626161d
commit
2833ca478c
@ -155,13 +155,13 @@ fn install_one_crate(c: cargo, _path: str, cf: str, _p: pkg) {
|
||||
name = str::slice(name, 0u, ri as uint);
|
||||
}
|
||||
log #fmt["Installing: %s", name];
|
||||
let old = vec::map({|x| str::slice(x, 2u, str::byte_len(x))},
|
||||
fs::list_dir("."));
|
||||
let old = vec::map(fs::list_dir("."),
|
||||
{|x| str::slice(x, 2u, str::byte_len(x))});
|
||||
run::run_program("rustc", [name + ".rc"]);
|
||||
let new = vec::map({|x| str::slice(x, 2u, str::byte_len(x))},
|
||||
fs::list_dir("."));
|
||||
let new = vec::map(fs::list_dir("."),
|
||||
{|x| str::slice(x, 2u, str::byte_len(x))});
|
||||
let created =
|
||||
vec::filter::<str>({ |n| !vec::member::<str>(n, old) }, new);
|
||||
vec::filter::<str>(new, { |n| !vec::member::<str>(n, old) });
|
||||
let exec_suffix = os::exec_suffix();
|
||||
for ct: str in created {
|
||||
if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
|
||||
@ -184,7 +184,7 @@ fn install_source(c: cargo, path: str) {
|
||||
log #fmt["contents: %s", str::connect(contents, ", ")];
|
||||
|
||||
let cratefiles =
|
||||
vec::filter::<str>({ |n| str::ends_with(n, ".rc") }, contents);
|
||||
vec::filter::<str>(contents, { |n| str::ends_with(n, ".rc") });
|
||||
|
||||
if vec::is_empty(cratefiles) {
|
||||
fail "This doesn't look like a rust package (no .rc files).";
|
||||
|
@ -47,7 +47,7 @@ fn get_sysroot_absolute_rt_lib(sess: session::session) -> fs::path {
|
||||
}
|
||||
|
||||
fn rpaths_to_flags(rpaths: [str]) -> [str] {
|
||||
vec::map({ |rpath| #fmt("-Wl,-rpath,%s",rpath)}, rpaths)
|
||||
vec::map(rpaths, { |rpath| #fmt("-Wl,-rpath,%s",rpath)})
|
||||
}
|
||||
|
||||
fn get_rpaths(os: session::os, cwd: fs::path, sysroot: fs::path,
|
||||
@ -96,7 +96,7 @@ fn get_rpaths_relative_to_output(os: session::os,
|
||||
cwd: fs::path,
|
||||
output: fs::path,
|
||||
libs: [fs::path]) -> [str] {
|
||||
vec::map(bind get_rpath_relative_to_output(os, cwd, output, _), libs)
|
||||
vec::map(libs, bind get_rpath_relative_to_output(os, cwd, output, _))
|
||||
}
|
||||
|
||||
fn get_rpath_relative_to_output(os: session::os,
|
||||
@ -150,7 +150,7 @@ fn get_relative_to(abs1: fs::path, abs2: fs::path) -> fs::path {
|
||||
}
|
||||
|
||||
fn get_absolute_rpaths(cwd: fs::path, libs: [fs::path]) -> [str] {
|
||||
vec::map(bind get_absolute_rpath(cwd, _), libs)
|
||||
vec::map(libs, bind get_absolute_rpath(cwd, _))
|
||||
}
|
||||
|
||||
fn get_absolute_rpath(cwd: fs::path, &&lib: fs::path) -> str {
|
||||
|
@ -650,10 +650,9 @@ fn main(args: [str]) {
|
||||
let ofile = getopts::opt_maybe_str(match, "o");
|
||||
let cfg = build_configuration(sess, binary, ifile);
|
||||
let pretty =
|
||||
option::map::<str,
|
||||
pp_mode>(bind parse_pretty(sess, _),
|
||||
getopts::opt_default(match, "pretty",
|
||||
"normal"));
|
||||
option::map(getopts::opt_default(match, "pretty",
|
||||
"normal"),
|
||||
bind parse_pretty(sess, _));
|
||||
alt pretty {
|
||||
some::<pp_mode>(ppm) { pretty_print_input(sess, cfg, ifile, ppm); ret; }
|
||||
none::<pp_mode>. {/* continue */ }
|
||||
|
@ -50,7 +50,7 @@ fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
|
||||
option::some(a)
|
||||
} else { option::none }
|
||||
}(_, name);
|
||||
ret vec::filter_map(filter, attrs);
|
||||
ret vec::filter_map(attrs, filter);
|
||||
}
|
||||
|
||||
fn get_attr_name(attr: ast::attribute) -> ast::ident {
|
||||
@ -66,7 +66,7 @@ fn find_meta_items_by_name(metas: [@ast::meta_item], name: ast::ident) ->
|
||||
option::some(m)
|
||||
} else { option::none }
|
||||
}(_, name);
|
||||
ret vec::filter_map(filter, metas);
|
||||
ret vec::filter_map(metas, filter);
|
||||
}
|
||||
|
||||
fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
|
||||
@ -186,7 +186,7 @@ fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) ->
|
||||
} else { option::none }
|
||||
}(_, name);
|
||||
|
||||
ret vec::filter_map(filter, items);
|
||||
ret vec::filter_map(items, filter);
|
||||
}
|
||||
|
||||
fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) {
|
||||
|
@ -29,9 +29,9 @@ fn filter_item(cfg: ast::crate_cfg, &&item: @ast::item) ->
|
||||
fn fold_mod(cfg: ast::crate_cfg, m: ast::_mod, fld: fold::ast_fold) ->
|
||||
ast::_mod {
|
||||
let filter = bind filter_item(cfg, _);
|
||||
let filtered_items = vec::filter_map(filter, m.items);
|
||||
ret {view_items: vec::map(fld.fold_view_item, m.view_items),
|
||||
items: vec::map(fld.fold_item, filtered_items)};
|
||||
let filtered_items = vec::filter_map(m.items, filter);
|
||||
ret {view_items: vec::map(m.view_items, fld.fold_view_item),
|
||||
items: vec::map(filtered_items, fld.fold_item)};
|
||||
}
|
||||
|
||||
fn filter_native_item(cfg: ast::crate_cfg, &&item: @ast::native_item) ->
|
||||
@ -44,8 +44,8 @@ fn filter_native_item(cfg: ast::crate_cfg, &&item: @ast::native_item) ->
|
||||
fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod,
|
||||
fld: fold::ast_fold) -> ast::native_mod {
|
||||
let filter = bind filter_native_item(cfg, _);
|
||||
let filtered_items = vec::filter_map(filter, nm.items);
|
||||
ret {view_items: vec::map(fld.fold_view_item, nm.view_items),
|
||||
let filtered_items = vec::filter_map(nm.items, filter);
|
||||
ret {view_items: vec::map(nm.view_items, fld.fold_view_item),
|
||||
items: filtered_items};
|
||||
}
|
||||
|
||||
@ -69,10 +69,10 @@ fn filter_stmt(cfg: ast::crate_cfg, &&stmt: @ast::stmt) ->
|
||||
fn fold_block(cfg: ast::crate_cfg, b: ast::blk_, fld: fold::ast_fold) ->
|
||||
ast::blk_ {
|
||||
let filter = bind filter_stmt(cfg, _);
|
||||
let filtered_stmts = vec::filter_map(filter, b.stmts);
|
||||
let filtered_stmts = vec::filter_map(b.stmts, filter);
|
||||
ret {view_items: b.view_items,
|
||||
stmts: vec::map(fld.fold_stmt, filtered_stmts),
|
||||
expr: option::map(fld.fold_expr, b.expr),
|
||||
stmts: vec::map(filtered_stmts, fld.fold_stmt),
|
||||
expr: option::map(b.expr, fld.fold_expr),
|
||||
id: b.id,
|
||||
rules: b.rules};
|
||||
}
|
||||
@ -99,8 +99,8 @@ fn metas_in_cfg(cfg: ast::crate_cfg, metas: [@ast::meta_item]) -> bool {
|
||||
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
|
||||
// so we can match against them. This is the list of configurations for
|
||||
// which the item is valid
|
||||
let cfg_metas = vec::concat(vec::filter_map(
|
||||
{|&&i| attr::get_meta_item_list(i)}, cfg_metas));
|
||||
let cfg_metas = vec::concat(vec::filter_map(cfg_metas,
|
||||
{|&&i| attr::get_meta_item_list(i)}));
|
||||
|
||||
let has_cfg_metas = vec::len(cfg_metas) > 0u;
|
||||
if !has_cfg_metas { ret true; }
|
||||
|
@ -61,7 +61,7 @@ fn fold_mod(_cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
|
||||
}
|
||||
|
||||
let mod_nomain =
|
||||
{view_items: m.view_items, items: vec::filter_map(nomain, m.items)};
|
||||
{view_items: m.view_items, items: vec::filter_map(m.items, nomain)};
|
||||
ret fold::noop_fold_mod(mod_nomain, fld);
|
||||
}
|
||||
|
||||
@ -126,8 +126,8 @@ fn is_test_fn(i: @ast::item) -> bool {
|
||||
fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool {
|
||||
let ignoreattrs = attr::find_attrs_by_name(i.attrs, "ignore");
|
||||
let ignoreitems = attr::attr_metas(ignoreattrs);
|
||||
let cfg_metas = vec::concat(vec::filter_map(
|
||||
{|&&i| attr::get_meta_item_list(i)}, ignoreitems));
|
||||
let cfg_metas = vec::concat(vec::filter_map(ignoreitems,
|
||||
{|&&i| attr::get_meta_item_list(i)}));
|
||||
ret if vec::is_not_empty(ignoreitems) {
|
||||
config::metas_in_cfg(cx.crate.node.config, cfg_metas)
|
||||
} else {
|
||||
|
@ -140,7 +140,7 @@ fn get_dep_hashes(cstore: cstore) -> [str] {
|
||||
log #fmt(" hash[%s]: %s", x.name, x.hash);
|
||||
}
|
||||
fn mapper(ch: crate_hash) -> str { ret ch.hash; }
|
||||
ret vec::map(mapper, sorted);
|
||||
ret vec::map(sorted, mapper);
|
||||
}
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
|
@ -159,7 +159,6 @@ fn resolve_path(path: [ast::ident], data: @[u8]) -> [ast::def_id] {
|
||||
ret result;
|
||||
}
|
||||
|
||||
|
||||
// FIXME doesn't yet handle renamed re-exported externals
|
||||
fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
|
||||
ast::def {
|
||||
|
@ -610,7 +610,7 @@ fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) {
|
||||
fn name(kv: numname) -> str { kv.ident }
|
||||
// mutable -> immutable hack for vec::map
|
||||
let immpairs = vec::slice(pairs, 0u, vec::len(pairs));
|
||||
ret vec::map(name, immpairs);
|
||||
ret vec::map(immpairs, name);
|
||||
}
|
||||
|
||||
// We're just going to write a list of crate names, with the assumption
|
||||
|
@ -325,7 +325,7 @@ fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope,
|
||||
for pat in a.pats {
|
||||
for proot in pattern_roots(cx.tcx, root.mut, pat) {
|
||||
let canon_id = pat_id_map.get(proot.name);
|
||||
alt vec::find({|x| x.id == canon_id}, binding_info) {
|
||||
alt vec::find(binding_info, {|x| x.id == canon_id}) {
|
||||
some(s) { s.unsafe_tys += unsafe_set(proot.mut); }
|
||||
none. {
|
||||
binding_info += [
|
||||
@ -683,7 +683,7 @@ fn filter_invalid(src: list<@invalid>, bs: [binding]) -> list<@invalid> {
|
||||
while cur != list::nil {
|
||||
alt cur {
|
||||
list::cons(head, tail) {
|
||||
let p = vec::position_pred({|b| b.node_id == head.node_id}, bs);
|
||||
let p = vec::position_pred(bs, {|b| b.node_id == head.node_id});
|
||||
if !is_none(p) { out = list::cons(head, @out); }
|
||||
cur = *tail;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
let t = ty::expr_ty(cx.tcx, ex);
|
||||
let ty_fields = alt ty::struct(cx.tcx, t) { ty::ty_rec(f) { f } };
|
||||
for tf in ty_fields {
|
||||
if !vec::any({|f| f.node.ident == tf.ident}, fields) &&
|
||||
if !vec::any(fields, {|f| f.node.ident == tf.ident}) &&
|
||||
!kind_can_be_copied(ty::type_kind(cx.tcx, tf.mt.ty)) {
|
||||
cx.tcx.sess.span_err(ex.span,
|
||||
"copying a noncopyable value");
|
||||
|
@ -197,7 +197,7 @@ fn join_branches(branches: [set]) -> set {
|
||||
for set in branches {
|
||||
i += 1u;
|
||||
for {def, exprs} in set {
|
||||
if !vec::any({|v| v.def == def}, found) {
|
||||
if !vec::any(found, {|v| v.def == def}) {
|
||||
let j = i, ne = exprs;
|
||||
while j < l {
|
||||
for {def: d2, exprs} in branches[j] {
|
||||
@ -234,8 +234,8 @@ fn clear_in_current(cx: ctx, my_def: node_id, to: bool) {
|
||||
cx.last_uses.insert(expr, to);
|
||||
}
|
||||
}
|
||||
cx.current = vec::filter({|x| x.def != my_def},
|
||||
copy cx.current);
|
||||
cx.current = vec::filter(copy cx.current,
|
||||
{|x| x.def != my_def});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1152,8 +1152,8 @@ fn lookup_in_globs(e: env, globs: [glob_imp_def], sp: span, id: ident,
|
||||
none. { none }
|
||||
}
|
||||
}
|
||||
let matches = vec::filter_map(bind lookup_in_mod_(e, _, sp, id, ns, dr),
|
||||
copy globs);
|
||||
let matches = vec::filter_map(copy globs,
|
||||
bind lookup_in_mod_(e, _, sp, id, ns, dr));
|
||||
if vec::len(matches) == 0u {
|
||||
ret none;
|
||||
} else if vec::len(matches) == 1u {
|
||||
@ -1448,7 +1448,7 @@ fn check_arm(e: @env, a: ast::arm, &&x: (), v: vt<()>) {
|
||||
"inconsistent number of bindings");
|
||||
} else {
|
||||
for name: ident in ch.seen {
|
||||
if is_none(vec::find(bind str::eq(name, _), seen0)) {
|
||||
if is_none(vec::find(seen0, bind str::eq(name, _))) {
|
||||
// Fight the alias checker
|
||||
let name_ = name;
|
||||
e.sess.span_err(a.pats[i].span,
|
||||
|
@ -3428,9 +3428,9 @@ fn trans_rec(bcx: @block_ctxt, fields: [ast::field],
|
||||
let ty_fields = alt ty::struct(bcx_tcx(bcx), t) { ty::ty_rec(f) { f } };
|
||||
let temp_cleanups = [];
|
||||
for fld in fields {
|
||||
let ix = option::get(vec::position_pred({|ft|
|
||||
let ix = option::get(vec::position_pred(ty_fields, {|ft|
|
||||
str::eq(fld.node.ident, ft.ident)
|
||||
}, ty_fields));
|
||||
}));
|
||||
let dst = GEP_tup_like_1(bcx, t, addr, [0, ix as int]);
|
||||
bcx = trans_expr_save_in(dst.bcx, fld.node.expr, dst.val);
|
||||
add_clean_temp_mem(bcx, dst.val, ty_fields[ix].mt.ty);
|
||||
@ -3442,7 +3442,7 @@ fn trans_rec(bcx: @block_ctxt, fields: [ast::field],
|
||||
bcx = cx;
|
||||
// Copy over inherited fields
|
||||
for tf in ty_fields {
|
||||
if !vec::any({|f| str::eq(f.node.ident, tf.ident)}, fields) {
|
||||
if !vec::any(fields, {|f| str::eq(f.node.ident, tf.ident)}) {
|
||||
let dst = GEP_tup_like_1(bcx, t, addr, [0, i]);
|
||||
let base = GEP_tup_like_1(bcx, t, base_val, [0, i]);
|
||||
let val = load_if_immediate(base.bcx, base.val, tf.mt.ty);
|
||||
|
@ -291,7 +291,7 @@ fn collect_record_fields(m: match, col: uint) -> [ast::ident] {
|
||||
alt br.pats[col].node {
|
||||
ast::pat_rec(fs, _) {
|
||||
for f: ast::field_pat in fs {
|
||||
if !vec::any(bind str::eq(f.ident, _), fields) {
|
||||
if !vec::any(fields, bind str::eq(f.ident, _)) {
|
||||
fields += [f.ident];
|
||||
}
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
|
||||
// Actually construct the closure
|
||||
let {llbox, box_ty, bcx} = store_environment(
|
||||
bcx, lltydescs,
|
||||
env_vals + vec::map({|x| env_expr(x)}, bound),
|
||||
env_vals + vec::map(bound, {|x| env_expr(x)}),
|
||||
ty::closure_shared);
|
||||
|
||||
// Make thunk
|
||||
|
@ -244,8 +244,8 @@ fn trans_anon_obj(bcx: @block_ctxt, sp: span, anon_obj: ast::anon_obj,
|
||||
// methods, not inner ones.
|
||||
let wrapper_obj: ast::_obj =
|
||||
{fields:
|
||||
vec::map(ast_util::obj_field_from_anon_obj_field,
|
||||
additional_fields),
|
||||
vec::map(additional_fields,
|
||||
ast_util::obj_field_from_anon_obj_field),
|
||||
methods: anon_obj.methods};
|
||||
|
||||
let inner_obj_ty: ty::t;
|
||||
@ -481,7 +481,7 @@ fn create_vtbl(cx: @local_ctxt, sp: span, outer_obj_ty: ty::t, ob: ast::_obj,
|
||||
// Filter out any methods that we don't need forwarding slots for
|
||||
// because they're being overridden.
|
||||
let f = bind filtering_fn(cx, _, ob.methods);
|
||||
meths = vec::filter_map(f, meths);
|
||||
meths = vec::filter_map(meths, f);
|
||||
|
||||
// And now add the additional ones, both overriding ones and entirely
|
||||
// new ones. These will just be normal methods.
|
||||
|
@ -1083,7 +1083,7 @@ fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> [init_op] {
|
||||
fn mode_to_op(m: ty::mode) -> init_op {
|
||||
alt m { by_move. { init_move } _ { init_assign } }
|
||||
}
|
||||
vec::map(mode_to_op, callee_modes(fcx, callee))
|
||||
vec::map(callee_modes(fcx, callee), mode_to_op)
|
||||
}
|
||||
|
||||
fn anon_bindings(ops: [init_op], es: [@expr]) -> [binding] {
|
||||
|
@ -95,10 +95,10 @@ fn find_pre_post_exprs(fcx: fn_ctxt, args: [@expr], id: node_id) {
|
||||
fn get_pp(ccx: crate_ctxt, &&e: @expr) -> pre_and_post {
|
||||
ret expr_pp(ccx, e);
|
||||
}
|
||||
let pps = vec::map(bind get_pp(fcx.ccx, _), args);
|
||||
let pps = vec::map(args, bind get_pp(fcx.ccx, _));
|
||||
|
||||
set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, pps),
|
||||
seq_postconds(fcx, vec::map(get_post, pps)));
|
||||
seq_postconds(fcx, vec::map(pps, get_post)));
|
||||
}
|
||||
|
||||
fn find_pre_post_loop(fcx: fn_ctxt, l: @local, index: @expr, body: blk,
|
||||
@ -472,7 +472,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
|
||||
postcondition: false_postcond(num_local_vars)};
|
||||
let g = bind combine_pp(antec_pp, fcx, _, _);
|
||||
let alts_overall_pp =
|
||||
vec::foldl::<pre_and_post, pre_and_post>(g, e_pp, alt_pps);
|
||||
vec::foldl(e_pp, alt_pps, g);
|
||||
set_pre_and_post(fcx.ccx, e.id, alts_overall_pp.precondition,
|
||||
alts_overall_pp.postcondition);
|
||||
}
|
||||
@ -669,7 +669,7 @@ fn find_pre_post_block(fcx: fn_ctxt, b: blk) {
|
||||
for s: @stmt in b.node.stmts { do_one_(fcx, s); }
|
||||
fn do_inner_(fcx: fn_ctxt, &&e: @expr) { find_pre_post_expr(fcx, e); }
|
||||
let do_inner = bind do_inner_(fcx, _);
|
||||
option::map::<@expr, ()>(do_inner, b.node.expr);
|
||||
option::map::<@expr, ()>(b.node.expr, do_inner);
|
||||
|
||||
let pps: [pre_and_post] = [];
|
||||
for s: @stmt in b.node.stmts { pps += [stmt_pp(fcx.ccx, *s)]; }
|
||||
|
@ -1708,7 +1708,7 @@ fn field_idx(sess: session::session, sp: span, id: ast::ident,
|
||||
fn get_field(tcx: ctxt, rec_ty: t, id: ast::ident) -> field {
|
||||
alt struct(tcx, rec_ty) {
|
||||
ty_rec(fields) {
|
||||
alt vec::find({|f| str::eq(f.ident, id) }, fields) {
|
||||
alt vec::find(fields, {|f| str::eq(f.ident, id) }) {
|
||||
some(f) { ret f; }
|
||||
}
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
|
||||
typ = ty::mk_ptr(tcx, ast_mt_to_mt(tcx, mode, mt));
|
||||
}
|
||||
ast::ty_tup(fields) {
|
||||
let flds = vec::map(bind ast_ty_to_ty(tcx, mode, _), fields);
|
||||
let flds = vec::map(fields, bind ast_ty_to_ty(tcx, mode, _));
|
||||
typ = ty::mk_tup(tcx, flds);
|
||||
}
|
||||
ast::ty_rec(fields) {
|
||||
@ -516,8 +516,8 @@ fn ty_of_native_fn_decl(tcx: ty::ctxt, mode: mode, decl: ast::fn_decl,
|
||||
ret tpt;
|
||||
}
|
||||
fn ty_of_method(tcx: ty::ctxt, mode: mode, m: @ast::method) -> ty::method {
|
||||
let inputs = vec::map({|i| ty_of_arg(tcx, mode, i)},
|
||||
m.node.meth.decl.inputs);
|
||||
let inputs = vec::map(m.node.meth.decl.inputs,
|
||||
{|i| ty_of_arg(tcx, mode, i)});
|
||||
let output = ast_ty_to_ty(tcx, mode, m.node.meth.decl.output);
|
||||
|
||||
let out_constrs = [];
|
||||
@ -540,7 +540,7 @@ fn ty_of_obj(tcx: ty::ctxt, mode: mode, id: ast::ident, ob: ast::_obj,
|
||||
}
|
||||
fn ty_of_obj_methods(tcx: ty::ctxt, mode: mode, object: ast::_obj)
|
||||
-> [ty::method] {
|
||||
vec::map({|m| ty_of_method(tcx, mode, m)}, object.methods)
|
||||
vec::map(object.methods, {|m| ty_of_method(tcx, mode, m)})
|
||||
}
|
||||
fn ty_of_obj_ctor(tcx: ty::ctxt, mode: mode, id: ast::ident, ob: ast::_obj,
|
||||
ctor_id: ast::node_id, ty_params: [ast::ty_param])
|
||||
@ -1331,7 +1331,7 @@ fn check_pat(fcx: @fn_ctxt, map: ast_util::pat_id_map, pat: @ast::pat,
|
||||
ret str::eq(name, f.ident);
|
||||
}
|
||||
for f: ast::field_pat in fields {
|
||||
alt vec::find(bind matches(f.ident, _), ex_fields) {
|
||||
alt vec::find(ex_fields, bind matches(f.ident, _)) {
|
||||
some(field) { check_pat(fcx, map, f.pat, field.mt.ty); }
|
||||
none. {
|
||||
fcx.ccx.tcx.sess.span_fatal(pat.span,
|
||||
@ -2091,7 +2091,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
||||
alt base {
|
||||
none. {
|
||||
fn get_node(f: spanned<field>) -> field { f.node }
|
||||
let typ = ty::mk_rec(tcx, vec::map(get_node, fields_t));
|
||||
let typ = ty::mk_rec(tcx, vec::map(fields_t, get_node));
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
some(bexpr) {
|
||||
@ -2140,7 +2140,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
||||
ids += b.ids;
|
||||
fty = b.ty;
|
||||
}
|
||||
let substs = vec::map({|id| ty::mk_var(tcx, id)}, ids);
|
||||
let substs = vec::map(ids, {|id| ty::mk_var(tcx, id)});
|
||||
write::ty_fixup(fcx, id, {substs: some(substs), ty: fty});
|
||||
fcx.ccx.method_map.insert(id, local_def(method.node.id));
|
||||
}
|
||||
@ -2268,7 +2268,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
||||
}
|
||||
|
||||
let f = bind filtering_fn(fcx.ccx, _, ao.methods);
|
||||
inner_obj_methods = vec::filter_map(f, inner_obj_methods);
|
||||
inner_obj_methods = vec::filter_map(inner_obj_methods, f);
|
||||
|
||||
method_types += inner_obj_methods;
|
||||
}
|
||||
@ -2287,8 +2287,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
||||
}
|
||||
|
||||
fcx.ccx.self_infos +=
|
||||
[self_obj(vec::map(ast_util::obj_field_from_anon_obj_field,
|
||||
fields), ot)];
|
||||
[self_obj(
|
||||
vec::map(fields, ast_util::obj_field_from_anon_obj_field),
|
||||
ot)];
|
||||
// Typecheck the methods.
|
||||
for method: @ast::method in ao.methods {
|
||||
check_method(fcx.ccx, method);
|
||||
|
@ -265,7 +265,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
recur: fn@(&&@expr) -> @expr, exprs: [@expr]) -> [@expr] {
|
||||
alt elts_to_ell(cx, exprs) {
|
||||
{pre: pre, rep: repeat_me_maybe, post: post} {
|
||||
let res = vec::map(recur, pre);
|
||||
let res = vec::map(pre, recur);
|
||||
alt repeat_me_maybe {
|
||||
none. { }
|
||||
some(repeat_me) {
|
||||
@ -314,7 +314,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
|
||||
}
|
||||
}
|
||||
}
|
||||
res += vec::map(recur, post);
|
||||
res += vec::map(post, recur);
|
||||
ret res;
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
|
||||
meta_word(id) { meta_word(fld.fold_ident(id)) }
|
||||
meta_list(id, mis) {
|
||||
let fold_meta_item = bind fold_meta_item_(_, fld);
|
||||
meta_list(id, vec::map(fold_meta_item, mis))
|
||||
meta_list(id, vec::map(mis, fold_meta_item))
|
||||
}
|
||||
meta_name_value(id, s) {
|
||||
meta_name_value(fld.fold_ident(id), s)
|
||||
@ -150,10 +150,10 @@ fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
|
||||
let fold_meta_item = bind fold_meta_item_(_, fld);
|
||||
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
|
||||
|
||||
ret {directives: vec::map(fld.fold_crate_directive, c.directives),
|
||||
ret {directives: vec::map(c.directives, fld.fold_crate_directive),
|
||||
module: fld.fold_mod(c.module),
|
||||
attrs: vec::map(fold_attribute, c.attrs),
|
||||
config: vec::map(fold_meta_item, c.config)};
|
||||
attrs: vec::map(c.attrs, fold_attribute),
|
||||
config: vec::map(c.config, fold_meta_item)};
|
||||
}
|
||||
|
||||
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
|
||||
@ -164,7 +164,7 @@ fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
|
||||
}
|
||||
cdir_dir_mod(id, cds, attrs) {
|
||||
cdir_dir_mod(fld.fold_ident(id),
|
||||
vec::map(fld.fold_crate_directive, cds), attrs)
|
||||
vec::map(cds, fld.fold_crate_directive), attrs)
|
||||
}
|
||||
cdir_view_item(vi) { cdir_view_item(fld.fold_view_item(vi)) }
|
||||
cdir_syntax(_) { cd }
|
||||
@ -182,19 +182,19 @@ fn noop_fold_native_item(&&ni: @native_item, fld: ast_fold) -> @native_item {
|
||||
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
|
||||
|
||||
ret @{ident: fld.fold_ident(ni.ident),
|
||||
attrs: vec::map(fold_attribute, ni.attrs),
|
||||
attrs: vec::map(ni.attrs, fold_attribute),
|
||||
node:
|
||||
alt ni.node {
|
||||
native_item_ty. { native_item_ty }
|
||||
native_item_fn(fdec, typms) {
|
||||
native_item_fn({inputs: vec::map(fold_arg, fdec.inputs),
|
||||
native_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
|
||||
output: fld.fold_ty(fdec.output),
|
||||
purity: fdec.purity,
|
||||
il: fdec.il,
|
||||
cf: fdec.cf,
|
||||
constraints:
|
||||
vec::map(fld.fold_constr,
|
||||
fdec.constraints)}, typms)
|
||||
vec::map(fdec.constraints,
|
||||
fld.fold_constr)}, typms)
|
||||
}
|
||||
},
|
||||
id: ni.id,
|
||||
@ -206,7 +206,7 @@ fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
|
||||
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
|
||||
|
||||
ret @{ident: fld.fold_ident(i.ident),
|
||||
attrs: vec::map(fold_attribute, i.attrs),
|
||||
attrs: vec::map(i.attrs, fold_attribute),
|
||||
id: i.id,
|
||||
node: fld.fold_item_underscore(i.node),
|
||||
span: i.span};
|
||||
@ -228,16 +228,16 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
|
||||
item_native_mod(nm) { item_native_mod(fld.fold_native_mod(nm)) }
|
||||
item_ty(t, typms) { item_ty(fld.fold_ty(t), typms) }
|
||||
item_tag(variants, typms) {
|
||||
item_tag(vec::map(fld.fold_variant, variants), typms)
|
||||
item_tag(vec::map(variants, fld.fold_variant), typms)
|
||||
}
|
||||
item_obj(o, typms, d) {
|
||||
item_obj({fields: vec::map(fold_obj_field, o.fields),
|
||||
methods: vec::map(fld.fold_method, o.methods)},
|
||||
item_obj({fields: vec::map(o.fields, fold_obj_field),
|
||||
methods: vec::map(o.methods, fld.fold_method)},
|
||||
typms, d)
|
||||
}
|
||||
item_impl(tps, ty, methods) {
|
||||
item_impl(tps, fld.fold_ty(ty),
|
||||
vec::map(fld.fold_method, methods))
|
||||
vec::map(methods, fld.fold_method))
|
||||
}
|
||||
item_res(dtor, did, typms, cid) {
|
||||
item_res(fld.fold_fn(dtor), did, typms, cid)
|
||||
@ -252,9 +252,9 @@ fn noop_fold_method(m: method_, fld: ast_fold) -> method_ {
|
||||
|
||||
|
||||
fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
|
||||
ret {view_items: vec::map(fld.fold_view_item, b.view_items),
|
||||
stmts: vec::map(fld.fold_stmt, b.stmts),
|
||||
expr: option::map(fld.fold_expr, b.expr),
|
||||
ret {view_items: vec::map(b.view_items, fld.fold_view_item),
|
||||
stmts: vec::map(b.stmts, fld.fold_stmt),
|
||||
expr: option::map(b.expr, fld.fold_expr),
|
||||
id: b.id,
|
||||
rules: b.rules};
|
||||
}
|
||||
@ -267,8 +267,8 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
|
||||
}
|
||||
|
||||
fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
|
||||
ret {pats: vec::map(fld.fold_pat, a.pats),
|
||||
guard: option::map(fld.fold_expr, a.guard),
|
||||
ret {pats: vec::map(a.pats, fld.fold_pat),
|
||||
guard: option::map(a.guard, fld.fold_expr),
|
||||
body: fld.fold_block(a.body)};
|
||||
}
|
||||
|
||||
@ -276,11 +276,11 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
||||
ret alt p {
|
||||
pat_wild. { p }
|
||||
pat_bind(ident, sub) {
|
||||
pat_bind(fld.fold_ident(ident), option::map(fld.fold_pat, sub))
|
||||
pat_bind(fld.fold_ident(ident), option::map(sub, fld.fold_pat))
|
||||
}
|
||||
pat_lit(_) { p }
|
||||
pat_tag(pth, pats) {
|
||||
pat_tag(fld.fold_path(pth), vec::map(fld.fold_pat, pats))
|
||||
pat_tag(fld.fold_path(pth), vec::map(pats, fld.fold_pat))
|
||||
}
|
||||
pat_rec(fields, etc) {
|
||||
let fs = [];
|
||||
@ -289,7 +289,7 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
||||
}
|
||||
pat_rec(fs, etc)
|
||||
}
|
||||
pat_tup(elts) { pat_tup(vec::map(fld.fold_pat, elts)) }
|
||||
pat_tup(elts) { pat_tup(vec::map(elts, fld.fold_pat)) }
|
||||
pat_box(inner) { pat_box(fld.fold_pat(inner)) }
|
||||
pat_uniq(inner) { pat_uniq(fld.fold_pat(inner)) }
|
||||
pat_range(_, _) { p }
|
||||
@ -299,8 +299,8 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
||||
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
|
||||
ret alt d {
|
||||
decl_local(ls) {
|
||||
decl_local(vec::map({|l| let (st, lc) = l;
|
||||
(st, fld.fold_local(lc))}, ls))
|
||||
decl_local(vec::map(ls, {|l| let (st, lc) = l;
|
||||
(st, fld.fold_local(lc))}))
|
||||
}
|
||||
decl_item(it) { decl_item(fld.fold_item(it)) }
|
||||
}
|
||||
@ -331,11 +331,11 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
alt ao.fields {
|
||||
option::none. { ao.fields }
|
||||
option::some(v) {
|
||||
option::some(vec::map(fold_anon_obj_field, v))
|
||||
option::some(vec::map(v, fold_anon_obj_field))
|
||||
}
|
||||
},
|
||||
methods: vec::map(fld.fold_method, ao.methods),
|
||||
inner_obj: option::map(fld.fold_expr, ao.inner_obj)}
|
||||
methods: vec::map(ao.methods, fld.fold_method),
|
||||
inner_obj: option::map(ao.inner_obj, fld.fold_expr)}
|
||||
}
|
||||
let fold_anon_obj = bind fold_anon_obj_(_, fld);
|
||||
|
||||
@ -346,17 +346,17 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
expr_vec(fld.map_exprs(fld.fold_expr, exprs), mut)
|
||||
}
|
||||
expr_rec(fields, maybe_expr) {
|
||||
expr_rec(vec::map(fold_field, fields),
|
||||
option::map(fld.fold_expr, maybe_expr))
|
||||
expr_rec(vec::map(fields, fold_field),
|
||||
option::map(maybe_expr, fld.fold_expr))
|
||||
}
|
||||
expr_tup(elts) { expr_tup(vec::map(fld.fold_expr, elts)) }
|
||||
expr_tup(elts) { expr_tup(vec::map(elts, fld.fold_expr)) }
|
||||
expr_call(f, args, blk) {
|
||||
expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args),
|
||||
blk)
|
||||
}
|
||||
expr_bind(f, args) {
|
||||
let opt_map_se = bind option::map(fld.fold_expr, _);
|
||||
expr_bind(fld.fold_expr(f), vec::map(opt_map_se, args))
|
||||
let opt_map_se = bind option::map(_, fld.fold_expr);
|
||||
expr_bind(fld.fold_expr(f), vec::map(args, opt_map_se))
|
||||
}
|
||||
expr_binary(binop, lhs, rhs) {
|
||||
expr_binary(binop, fld.fold_expr(lhs), fld.fold_expr(rhs))
|
||||
@ -366,7 +366,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
|
||||
expr_if(cond, tr, fl) {
|
||||
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
|
||||
option::map(fld.fold_expr, fl))
|
||||
option::map(fl, fld.fold_expr))
|
||||
}
|
||||
expr_ternary(cond, tr, fl) {
|
||||
expr_ternary(fld.fold_expr(cond), fld.fold_expr(tr),
|
||||
@ -383,7 +383,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
expr_do_while(fld.fold_block(blk), fld.fold_expr(expr))
|
||||
}
|
||||
expr_alt(expr, arms) {
|
||||
expr_alt(fld.fold_expr(expr), vec::map(fld.fold_arm, arms))
|
||||
expr_alt(fld.fold_expr(expr), vec::map(arms, fld.fold_arm))
|
||||
}
|
||||
// NDM fold_captures
|
||||
expr_fn(f, captures) { expr_fn(fld.fold_fn(f), captures) }
|
||||
@ -408,17 +408,17 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
expr_index(fld.fold_expr(el), fld.fold_expr(er))
|
||||
}
|
||||
expr_path(pth) { expr_path(fld.fold_path(pth)) }
|
||||
expr_fail(e) { expr_fail(option::map(fld.fold_expr, e)) }
|
||||
expr_fail(e) { expr_fail(option::map(e, fld.fold_expr)) }
|
||||
expr_break. { e }
|
||||
expr_cont. { e }
|
||||
expr_ret(e) { expr_ret(option::map(fld.fold_expr, e)) }
|
||||
expr_ret(e) { expr_ret(option::map(e, fld.fold_expr)) }
|
||||
expr_be(e) { expr_be(fld.fold_expr(e)) }
|
||||
expr_log(lv, e) { expr_log(lv, fld.fold_expr(e)) }
|
||||
expr_assert(e) { expr_assert(fld.fold_expr(e)) }
|
||||
expr_check(m, e) { expr_check(m, fld.fold_expr(e)) }
|
||||
expr_if_check(cond, tr, fl) {
|
||||
expr_if_check(fld.fold_expr(cond), fld.fold_block(tr),
|
||||
option::map(fld.fold_expr, fl))
|
||||
option::map(fl, fld.fold_expr))
|
||||
}
|
||||
expr_anon_obj(ao) { expr_anon_obj(fold_anon_obj(ao)) }
|
||||
expr_mac(mac) { expr_mac(fold_mac(mac)) }
|
||||
@ -439,25 +439,25 @@ fn noop_fold_fn(f: _fn, fld: ast_fold) -> _fn {
|
||||
let fold_arg = bind fold_arg_(_, fld);
|
||||
|
||||
ret {decl:
|
||||
{inputs: vec::map(fold_arg, f.decl.inputs),
|
||||
{inputs: vec::map(f.decl.inputs, fold_arg),
|
||||
output: fld.fold_ty(f.decl.output),
|
||||
purity: f.decl.purity,
|
||||
il: f.decl.il,
|
||||
cf: f.decl.cf,
|
||||
constraints: vec::map(fld.fold_constr, f.decl.constraints)},
|
||||
constraints: vec::map(f.decl.constraints, fld.fold_constr)},
|
||||
proto: f.proto,
|
||||
body: fld.fold_block(f.body)};
|
||||
}
|
||||
|
||||
// ...nor do modules
|
||||
fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
|
||||
ret {view_items: vec::map(fld.fold_view_item, m.view_items),
|
||||
items: vec::map(fld.fold_item, m.items)};
|
||||
ret {view_items: vec::map(m.view_items, fld.fold_view_item),
|
||||
items: vec::map(m.items, fld.fold_item)};
|
||||
}
|
||||
|
||||
fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod {
|
||||
ret {view_items: vec::map(fld.fold_view_item, nm.view_items),
|
||||
items: vec::map(fld.fold_native_item, nm.items)}
|
||||
ret {view_items: vec::map(nm.view_items, fld.fold_view_item),
|
||||
items: vec::map(nm.items, fld.fold_native_item)}
|
||||
}
|
||||
|
||||
fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
|
||||
@ -465,15 +465,15 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
|
||||
ret {ty: fld.fold_ty(va.ty), id: va.id};
|
||||
}
|
||||
let fold_variant_arg = bind fold_variant_arg_(_, fld);
|
||||
ret {name: v.name, args: vec::map(fold_variant_arg, v.args), id: v.id};
|
||||
ret {name: v.name, args: vec::map(v.args, fold_variant_arg), id: v.id};
|
||||
}
|
||||
|
||||
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }
|
||||
|
||||
fn noop_fold_path(p: path_, fld: ast_fold) -> path_ {
|
||||
ret {global: p.global,
|
||||
idents: vec::map(fld.fold_ident, p.idents),
|
||||
types: vec::map(fld.fold_ty, p.types)};
|
||||
idents: vec::map(p.idents, fld.fold_ident),
|
||||
types: vec::map(p.types, fld.fold_ty)};
|
||||
}
|
||||
|
||||
fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
|
||||
@ -493,7 +493,7 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
|
||||
/* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
|
||||
value */
|
||||
fn noop_map_exprs(f: fn@(&&@expr) -> @expr, es: [@expr]) -> [@expr] {
|
||||
ret vec::map(f, es);
|
||||
ret vec::map(es, f);
|
||||
}
|
||||
|
||||
fn noop_id(i: node_id) -> node_id { ret i; }
|
||||
|
@ -281,7 +281,7 @@ fn split_maybe_args(argstr: option::t<str>) -> [str] {
|
||||
for c: u8 in s { if c != ' ' as u8 { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
vec::filter_map(flt, v)
|
||||
vec::filter_map(v, flt)
|
||||
}
|
||||
|
||||
alt argstr {
|
||||
|
@ -220,7 +220,8 @@ fn as_str(f: fn@(io::writer)) -> str {
|
||||
fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
|
||||
filename: str, cx: context) {
|
||||
let stolen = steal(crate, cx.mode);
|
||||
let extra_exprs = vec::filter(bind safe_to_use_expr(_, cx.mode), common_exprs());
|
||||
let extra_exprs = vec::filter(common_exprs(),
|
||||
bind safe_to_use_expr(_, cx.mode));
|
||||
check_variants_T(crate, codemap, filename, "expr", extra_exprs + stolen.exprs, pprust::expr_to_str, replace_expr_in_crate, cx);
|
||||
check_variants_T(crate, codemap, filename, "ty", stolen.tys, pprust::ty_to_str, replace_ty_in_crate, cx);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ fn get<copy T>(opt: t<T>) -> T {
|
||||
|
||||
/*
|
||||
*/
|
||||
fn map<T, U>(f: block(T) -> U, opt: t<T>) -> t<U> {
|
||||
fn map<T, U>(opt: t<T>, f: block(T) -> U) -> t<U> {
|
||||
alt opt { some(x) { some(f(x)) } none. { none } }
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ Function: maybe
|
||||
|
||||
Applies a function to the contained value or returns a default
|
||||
*/
|
||||
fn maybe<T, U>(def: U, f: block(T) -> U, opt: t<T>) -> U {
|
||||
fn maybe<T, U>(def: U, opt: t<T>, f: block(T) -> U) -> U {
|
||||
alt opt { none. { def } some(t) { f(t) } }
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ Function: may
|
||||
|
||||
Performs an operation on the contained value or does nothing
|
||||
*/
|
||||
fn may<T>(f: block(T), opt: t<T>) {
|
||||
fn may<T>(opt: t<T>, f: block(T)) {
|
||||
alt opt { none. {/* nothing */ } some(t) { f(t); } }
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ Function: map
|
||||
|
||||
Apply a function to each element of a vector and return the results
|
||||
*/
|
||||
fn map<T, U>(f: block(T) -> U, v: [T]) -> [U] {
|
||||
fn map<T, U>(v: [T], f: block(T) -> U) -> [U] {
|
||||
let result = [];
|
||||
reserve(result, len(v));
|
||||
for elem: T in v { result += [f(elem)]; }
|
||||
@ -396,7 +396,7 @@ Function: map_mut
|
||||
|
||||
Apply a function to each element of a mutable vector and return the results
|
||||
*/
|
||||
fn map_mut<copy T, U>(f: block(T) -> U, v: [const T]) -> [U] {
|
||||
fn map_mut<copy T, U>(v: [const T], f: block(T) -> U) -> [U] {
|
||||
let result = [];
|
||||
reserve(result, len(v));
|
||||
for elem: T in v {
|
||||
@ -411,7 +411,7 @@ Function: map2
|
||||
|
||||
Apply a function to each pair of elements and return the results
|
||||
*/
|
||||
fn map2<copy T, copy U, V>(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] {
|
||||
fn map2<copy T, copy U, V>(v0: [T], v1: [U], f: block(T, U) -> V) -> [V] {
|
||||
let v0_len = len(v0);
|
||||
if v0_len != len(v1) { fail; }
|
||||
let u: [V] = [];
|
||||
@ -428,7 +428,7 @@ Apply a function to each element of a vector and return the results
|
||||
If function `f` returns `none` then that element is excluded from
|
||||
the resulting vector.
|
||||
*/
|
||||
fn filter_map<copy T, copy U>(f: block(T) -> option::t<U>, v: [const T])
|
||||
fn filter_map<copy T, copy U>(v: [const T], f: block(T) -> option::t<U>)
|
||||
-> [U] {
|
||||
let result = [];
|
||||
for elem: T in v {
|
||||
@ -449,7 +449,7 @@ holds.
|
||||
Apply function `f` to each element of `v` and return a vector containing
|
||||
only those elements for which `f` returned true.
|
||||
*/
|
||||
fn filter<copy T>(f: block(T) -> bool, v: [T]) -> [T] {
|
||||
fn filter<copy T>(v: [T], f: block(T) -> bool) -> [T] {
|
||||
let result = [];
|
||||
for elem: T in v {
|
||||
if f(elem) { result += [elem]; }
|
||||
@ -474,7 +474,7 @@ Function: foldl
|
||||
|
||||
Reduce a vector from left to right
|
||||
*/
|
||||
fn foldl<copy T, U>(p: block(T, U) -> T, z: T, v: [const U]) -> T {
|
||||
fn foldl<copy T, U>(z: T, v: [const U], p: block(T, U) -> T) -> T {
|
||||
let accum = z;
|
||||
iter(v) { |elt|
|
||||
accum = p(accum, elt);
|
||||
@ -487,7 +487,7 @@ Function: foldr
|
||||
|
||||
Reduce a vector from right to left
|
||||
*/
|
||||
fn foldr<T, copy U>(p: block(T, U) -> U, z: U, v: [const T]) -> U {
|
||||
fn foldr<T, copy U>(v: [const T], z: U, p: block(T, U) -> U) -> U {
|
||||
let accum = z;
|
||||
riter(v) { |elt|
|
||||
accum = p(elt, accum);
|
||||
@ -502,7 +502,7 @@ Return true if a predicate matches any elements
|
||||
|
||||
If the vector contains no elements then false is returned.
|
||||
*/
|
||||
fn any<T>(f: block(T) -> bool, v: [T]) -> bool {
|
||||
fn any<T>(v: [T], f: block(T) -> bool) -> bool {
|
||||
for elem: T in v { if f(elem) { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
@ -514,7 +514,7 @@ Return true if a predicate matches all elements
|
||||
|
||||
If the vector contains no elements then true is returned.
|
||||
*/
|
||||
fn all<T>(f: block(T) -> bool, v: [T]) -> bool {
|
||||
fn all<T>(v: [T], f: block(T) -> bool) -> bool {
|
||||
for elem: T in v { if !f(elem) { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
@ -549,7 +549,7 @@ Apply function `f` to each element of `v`, starting from the first.
|
||||
When function `f` returns true then an option containing the element
|
||||
is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
fn find<copy T>(f: block(T) -> bool, v: [T]) -> option::t<T> {
|
||||
fn find<copy T>(v: [T], f: block(T) -> bool) -> option::t<T> {
|
||||
for elt: T in v { if f(elt) { ret some(elt); } }
|
||||
ret none;
|
||||
}
|
||||
@ -575,7 +575,7 @@ Function: position_pred
|
||||
|
||||
Find the first index for which the value matches some predicate
|
||||
*/
|
||||
fn position_pred<T>(f: block(T) -> bool, v: [T]) -> option::t<uint> {
|
||||
fn position_pred<T>(v: [T], f: block(T) -> bool) -> option::t<uint> {
|
||||
let i: uint = 0u;
|
||||
while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
|
||||
ret none;
|
||||
|
@ -317,13 +317,13 @@ fn normalize(p: path) -> path {
|
||||
ret s;
|
||||
|
||||
fn strip_dots(s: [path]) -> [path] {
|
||||
vec::filter_map({ |elem|
|
||||
vec::filter_map(s, { |elem|
|
||||
if elem == "." {
|
||||
option::none
|
||||
} else {
|
||||
option::some(elem)
|
||||
}
|
||||
}, s)
|
||||
})
|
||||
}
|
||||
|
||||
fn rollup_doubledots(s: [path]) -> [path] {
|
||||
|
@ -50,7 +50,7 @@ fn to_str(j: json) -> str {
|
||||
list(@js) {
|
||||
str::concat(["[",
|
||||
str::connect(
|
||||
vec::map::<json,str>({ |e| to_str(e) }, js),
|
||||
vec::map::<json,str>(js, { |e| to_str(e) }),
|
||||
", "),
|
||||
"]"])
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ Function: from_vec
|
||||
Create a list from a vector
|
||||
*/
|
||||
fn from_vec<copy T>(v: [const T]) -> list<T> {
|
||||
*vec::foldr({ |h, t| @cons(h, t) }, @nil::<T>, v)
|
||||
*vec::foldr(v, @nil::<T>, { |h, t| @cons(h, t) })
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -49,7 +49,7 @@ Failure:
|
||||
String must be a valid IPv4 address
|
||||
*/
|
||||
fn parse_addr(ip: str) -> ip_addr {
|
||||
let parts = vec::map({|s| uint::from_str(s) }, str::split(ip, "."[0]));
|
||||
let parts = vec::map(str::split(ip, "."[0]), {|s| uint::from_str(s) });
|
||||
if vec::len(parts) != 4u { fail "Too many dots in IP address"; }
|
||||
for i in parts { if i > 255u { fail "Invalid IP Address part."; } }
|
||||
ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8)
|
||||
|
@ -122,7 +122,7 @@ fn spawn_process(prog: str, args: [str], in_fd: fd_t,
|
||||
// Note: we have to hold on to these vector references while we hold a
|
||||
// pointer to their buffers
|
||||
let prog = prog;
|
||||
let args = vec::map({|arg| @arg }, args);
|
||||
let args = vec::map(args, {|arg| @arg });
|
||||
let argv = arg_vec(prog, args);
|
||||
let pid =
|
||||
rustrt::rust_run_program(vec::unsafe::to_ptr(argv), in_fd, out_fd,
|
||||
|
@ -276,7 +276,7 @@ fn filter_tests<copy T>(opts: test_opts,
|
||||
|
||||
let filter = bind filter_fn(_, filter_str);
|
||||
|
||||
vec::filter_map(filter, filtered)
|
||||
vec::filter_map(filtered, filter)
|
||||
};
|
||||
|
||||
// Maybe pull out the ignored test and unignore them
|
||||
@ -292,7 +292,7 @@ fn filter_tests<copy T>(opts: test_opts,
|
||||
} else { ret option::none; }
|
||||
};
|
||||
|
||||
vec::filter_map(bind filter(_), filtered)
|
||||
vec::filter_map(filtered, bind filter(_))
|
||||
};
|
||||
|
||||
// Sort the tests alphabetically
|
||||
|
@ -192,8 +192,8 @@ fn main(argv: [str]) {
|
||||
let inputs = if vec::len(argv) < 2u {
|
||||
[input1(), input2(), input3()]
|
||||
} else {
|
||||
vec::map({|f| result::get(io::read_whole_file_str(f)) },
|
||||
vec::slice(argv, 1u, vec::len(argv)))
|
||||
vec::map(vec::slice(argv, 1u, vec::len(argv)),
|
||||
{|f| result::get(io::read_whole_file_str(f)) })
|
||||
};
|
||||
|
||||
let start = time::precise_time_ns();
|
||||
|
@ -3,8 +3,9 @@ import vec;
|
||||
|
||||
fn main() {
|
||||
let v =
|
||||
vec::map2({|i, b| if b { -i } else { i } }, [1, 2, 3, 4, 5],
|
||||
[true, false, false, true, true]);
|
||||
vec::map2([1, 2, 3, 4, 5],
|
||||
[true, false, false, true, true],
|
||||
{|i, b| if b { -i } else { i } });
|
||||
log_err v;
|
||||
assert (v == [-1, 2, 3, -4, -5]);
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ fn checktests() {
|
||||
let tests = __test::tests();
|
||||
|
||||
let shouldignore = option::get(
|
||||
vec::find({|t| t.name == "shouldignore"}, tests));
|
||||
vec::find(tests, {|t| t.name == "shouldignore"}));
|
||||
assert shouldignore.ignore == true;
|
||||
|
||||
let shouldnotignore = option::get(
|
||||
vec::find({|t| t.name == "shouldnotignore"}, tests));
|
||||
vec::find(tests, {|t| t.name == "shouldnotignore"}));
|
||||
assert shouldnotignore.ignore == false;
|
||||
}
|
@ -213,7 +213,7 @@ fn test_grow_set() {
|
||||
fn test_map() {
|
||||
// Test on-stack map.
|
||||
let v = [1u, 2u, 3u];
|
||||
let w = vec::map(square_ref, v);
|
||||
let w = vec::map(v, square_ref);
|
||||
assert (vec::len(w) == 3u);
|
||||
assert (w[0] == 1u);
|
||||
assert (w[1] == 4u);
|
||||
@ -221,7 +221,7 @@ fn test_map() {
|
||||
|
||||
// Test on-heap map.
|
||||
v = [1u, 2u, 3u, 4u, 5u];
|
||||
w = vec::map(square_ref, v);
|
||||
w = vec::map(v, square_ref);
|
||||
assert (vec::len(w) == 5u);
|
||||
assert (w[0] == 1u);
|
||||
assert (w[1] == 4u);
|
||||
@ -236,7 +236,7 @@ fn test_map2() {
|
||||
let f = times;
|
||||
let v0 = [1, 2, 3, 4, 5];
|
||||
let v1 = [5, 4, 3, 2, 1];
|
||||
let u = vec::map2::<int, int, int>(f, v0, v1);
|
||||
let u = vec::map2::<int, int, int>(v0, v1, f);
|
||||
let i = 0;
|
||||
while i < 5 { assert (v0[i] * v1[i] == u[i]); i += 1; }
|
||||
}
|
||||
@ -245,14 +245,14 @@ fn test_map2() {
|
||||
fn test_filter_map() {
|
||||
// Test on-stack filter-map.
|
||||
let v = [1u, 2u, 3u];
|
||||
let w = vec::filter_map(square_if_odd, v);
|
||||
let w = vec::filter_map(v, square_if_odd);
|
||||
assert (vec::len(w) == 2u);
|
||||
assert (w[0] == 1u);
|
||||
assert (w[1] == 9u);
|
||||
|
||||
// Test on-heap filter-map.
|
||||
v = [1u, 2u, 3u, 4u, 5u];
|
||||
w = vec::filter_map(square_if_odd, v);
|
||||
w = vec::filter_map(v, square_if_odd);
|
||||
assert (vec::len(w) == 3u);
|
||||
assert (w[0] == 1u);
|
||||
assert (w[1] == 9u);
|
||||
@ -269,28 +269,28 @@ fn test_filter_map() {
|
||||
let all_odd2: [int] = [];
|
||||
let mix: [int] = [9, 2, 6, 7, 1, 0, 0, 3];
|
||||
let mix_dest: [int] = [1, 3, 0, 0];
|
||||
assert (filter_map(halve, all_even) == map(halve_for_sure, all_even));
|
||||
assert (filter_map(halve, all_odd1) == []);
|
||||
assert (filter_map(halve, all_odd2) == []);
|
||||
assert (filter_map(halve, mix) == mix_dest);
|
||||
assert (filter_map(all_even, halve) == map(all_even, halve_for_sure));
|
||||
assert (filter_map(all_odd1, halve) == []);
|
||||
assert (filter_map(all_odd2, halve) == []);
|
||||
assert (filter_map(mix, halve) == mix_dest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter() {
|
||||
assert filter(is_odd, [1u, 2u, 3u]) == [1u, 3u];
|
||||
assert filter(is_three, [1u, 2u, 4u, 8u, 16u]) == [];
|
||||
assert filter([1u, 2u, 3u], is_odd) == [1u, 3u];
|
||||
assert filter([1u, 2u, 4u, 8u, 16u], is_three) == [];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_foldl() {
|
||||
// Test on-stack fold.
|
||||
let v = [1u, 2u, 3u];
|
||||
let sum = vec::foldl(add, 0u, v);
|
||||
let sum = vec::foldl(0u, v, add);
|
||||
assert (sum == 6u);
|
||||
|
||||
// Test on-heap fold.
|
||||
v = [1u, 2u, 3u, 4u, 5u];
|
||||
sum = vec::foldl(add, 0u, v);
|
||||
sum = vec::foldl(0u, v, add);
|
||||
assert (sum == 15u);
|
||||
}
|
||||
|
||||
@ -300,7 +300,7 @@ fn test_foldl2() {
|
||||
a - b
|
||||
}
|
||||
let v = [1, 2, 3, 4];
|
||||
let sum = vec::foldl(sub, 0, v);
|
||||
let sum = vec::foldl(0, v, sub);
|
||||
assert sum == -10;
|
||||
}
|
||||
|
||||
@ -310,7 +310,7 @@ fn test_foldr() {
|
||||
a - b
|
||||
}
|
||||
let v = [1, 2, 3, 4];
|
||||
let sum = vec::foldr(sub, 0, v);
|
||||
let sum = vec::foldr(v, 0, sub);
|
||||
assert sum == -2;
|
||||
}
|
||||
|
||||
@ -390,15 +390,15 @@ fn test_permute() {
|
||||
|
||||
#[test]
|
||||
fn test_any_and_all() {
|
||||
assert (vec::any(is_three, [1u, 2u, 3u]));
|
||||
assert (!vec::any(is_three, [0u, 1u, 2u]));
|
||||
assert (vec::any(is_three, [1u, 2u, 3u, 4u, 5u]));
|
||||
assert (!vec::any(is_three, [1u, 2u, 4u, 5u, 6u]));
|
||||
assert (vec::any([1u, 2u, 3u], is_three));
|
||||
assert (!vec::any([0u, 1u, 2u], is_three));
|
||||
assert (vec::any([1u, 2u, 3u, 4u, 5u], is_three));
|
||||
assert (!vec::any([1u, 2u, 4u, 5u, 6u], is_three));
|
||||
|
||||
assert (vec::all(is_three, [3u, 3u, 3u]));
|
||||
assert (!vec::all(is_three, [3u, 3u, 2u]));
|
||||
assert (vec::all(is_three, [3u, 3u, 3u, 3u, 3u]));
|
||||
assert (!vec::all(is_three, [3u, 3u, 0u, 1u, 2u]));
|
||||
assert (vec::all([3u, 3u, 3u], is_three));
|
||||
assert (!vec::all([3u, 3u, 2u], is_three));
|
||||
assert (vec::all([3u, 3u, 3u, 3u, 3u], is_three));
|
||||
assert (!vec::all([3u, 3u, 0u, 1u, 2u], is_three));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -434,8 +434,8 @@ fn test_position_pred() {
|
||||
fn less_than_three(&&i: int) -> bool { ret i < 3; }
|
||||
fn is_eighteen(&&i: int) -> bool { ret i == 18; }
|
||||
let v1: [int] = [5, 4, 3, 2, 1];
|
||||
assert (position_pred(less_than_three, v1) == option::some::<uint>(3u));
|
||||
assert (position_pred(is_eighteen, v1) == option::none::<uint>);
|
||||
assert (position_pred(v1, less_than_three) == option::some::<uint>(3u));
|
||||
assert (position_pred(v1, is_eighteen) == option::none::<uint>);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user