s/block()/fn()/g

This commit is contained in:
Niko Matsakis 2012-01-23 14:59:00 -08:00
parent 04351a84ca
commit 5e13d19cc0
79 changed files with 152 additions and 155 deletions

View file

@ -349,7 +349,7 @@ fn configure() -> cargo {
c c
} }
fn for_each_package(c: cargo, b: block(source, package)) { fn for_each_package(c: cargo, b: fn(source, package)) {
c.sources.values({ |v| c.sources.values({ |v|
for p in copy v.packages { for p in copy v.packages {
b(v, p); b(v, p);

View file

@ -93,7 +93,7 @@ fn have_crate_data(cstore: cstore, cnum: ast::crate_num) -> bool {
ret p(cstore).metas.contains_key(cnum); ret p(cstore).metas.contains_key(cnum);
} }
fn iter_crate_data(cstore: cstore, i: block(ast::crate_num, crate_metadata)) { fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) {
p(cstore).metas.items {|k,v| i(k, v);}; p(cstore).metas.items {|k,v| i(k, v);};
} }

View file

@ -460,7 +460,7 @@ fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) {
out.write_str("\n"); out.write_str("\n");
} }
fn iter_crate_items(bytes: @[u8], proc: block(str, ast::def_id)) { fn iter_crate_items(bytes: @[u8], proc: fn(str, ast::def_id)) {
let md = ebml::new_doc(bytes); let md = ebml::new_doc(bytes);
let paths = ebml::get_doc(md, tag_paths); let paths = ebml::get_doc(md, tag_paths);
let index = ebml::get_doc(paths, tag_index); let index = ebml::get_doc(paths, tag_index);

View file

@ -486,7 +486,7 @@ fn create_index<T: copy>(index: [entry<T>], hash_fn: fn@(T) -> uint) ->
} }
fn encode_index<T>(ebml_w: ebml::writer, buckets: [@[entry<T>]], fn encode_index<T>(ebml_w: ebml::writer, buckets: [@[entry<T>]],
write_fn: block(io::writer, T)) { write_fn: fn(io::writer, T)) {
let writer = ebml_w.writer; let writer = ebml_w.writer;
ebml::start_tag(ebml_w, tag_index); ebml::start_tag(ebml_w, tag_index);
let bucket_locs: [uint] = []; let bucket_locs: [uint] = [];

View file

@ -16,7 +16,7 @@ export parse_bounds_data;
// data buffer. Whatever format you choose should not contain pipe characters. // data buffer. Whatever format you choose should not contain pipe characters.
// Callback to translate defs to strs or back: // Callback to translate defs to strs or back:
type conv_did = block(ast::def_id) -> ast::def_id; type conv_did = fn(ast::def_id) -> ast::def_id;
type pstate = {data: @[u8], crate: int, mutable pos: uint, tcx: ty::ctxt}; type pstate = {data: @[u8], crate: int, mutable pos: uint, tcx: ty::ctxt};
@ -138,7 +138,7 @@ fn parse_ty_constr_arg(st: @pstate) -> ast::constr_arg_general_<@path> {
} }
fn parse_constr<T: copy>(st: @pstate, conv: conv_did, fn parse_constr<T: copy>(st: @pstate, conv: conv_did,
pser: block(@pstate) -> ast::constr_arg_general_<T>) pser: fn(@pstate) -> ast::constr_arg_general_<T>)
-> @ty::constr_general<T> { -> @ty::constr_general<T> {
let sp = ast_util::dummy_sp(); // FIXME: use a real span let sp = ast_util::dummy_sp(); // FIXME: use a real span
let args: [@sp_constr_arg<T>] = []; let args: [@sp_constr_arg<T>] = [];

View file

@ -436,7 +436,7 @@ fn check_if(c: @ast::expr, then: ast::blk, els: option::t<@ast::expr>,
*sc.invalid = append_invalid(*sc.invalid, then_invalid, orig_invalid); *sc.invalid = append_invalid(*sc.invalid, then_invalid, orig_invalid);
} }
fn check_loop(cx: ctx, sc: scope, checker: block()) { fn check_loop(cx: ctx, sc: scope, checker: fn()) {
let orig_invalid = filter_invalid(*sc.invalid, sc.bs); let orig_invalid = filter_invalid(*sc.invalid, sc.bs);
checker(); checker();
let new_invalid = filter_invalid(*sc.invalid, sc.bs); let new_invalid = filter_invalid(*sc.invalid, sc.bs);

View file

@ -140,7 +140,7 @@ fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
} }
fn cached_metadata<T: copy>(cache: metadata_cache, mdtag: int, fn cached_metadata<T: copy>(cache: metadata_cache, mdtag: int,
eq: block(md: T) -> bool) -> option::t<T> unsafe { eq: fn(md: T) -> bool) -> option::t<T> unsafe {
if cache.contains_key(mdtag) { if cache.contains_key(mdtag) {
let items = cache.get(mdtag); let items = cache.get(mdtag);
for item in items { for item in items {

View file

@ -58,7 +58,7 @@ fn check_crate(tcx: ty::ctxt, method_map: typeck::method_map,
// variables. `id` is the node_id for some expression that creates the // variables. `id` is the node_id for some expression that creates the
// closure. // closure.
fn with_appropriate_checker(cx: ctx, id: node_id, fn with_appropriate_checker(cx: ctx, id: node_id,
b: block(fn@(ctx, ty::t, sp: span))) { b: fn(fn@(ctx, ty::t, sp: span))) {
let fty = ty::node_id_to_monotype(cx.tcx, id); let fty = ty::node_id_to_monotype(cx.tcx, id);
alt ty::ty_fn_proto(cx.tcx, fty) { alt ty::ty_fn_proto(cx.tcx, fty) {
proto_uniq { b(check_send); } proto_uniq { b(check_send); }

View file

@ -203,7 +203,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
} }
} }
fn visit_block(tp: block_type, cx: ctx, visit: block()) { fn visit_block(tp: block_type, cx: ctx, visit: fn()) {
let local = @{type: tp, mutable second: false, mutable exits: []}; let local = @{type: tp, mutable second: false, mutable exits: []};
cx.blocks = cons(local, @cx.blocks); cx.blocks = cons(local, @cx.blocks);
visit(); visit();

View file

@ -26,7 +26,7 @@ impl opt_ for option {
} }
// FIXME: Copied from driver.rs, to work around a bug(#1566) // FIXME: Copied from driver.rs, to work around a bug(#1566)
fn time(do_it: bool, what: str, thunk: block()) { fn time(do_it: bool, what: str, thunk: fn()) {
if !do_it{ ret thunk(); } if !do_it{ ret thunk(); }
let start = std::time::precise_time_s(); let start = std::time::precise_time_s();
thunk(); thunk();

View file

@ -91,7 +91,7 @@ fn pat_id_map(tcx: ty::ctxt, pat: @pat) -> pat_id_map {
// This does *not* normalize. The pattern should be already normalized // This does *not* normalize. The pattern should be already normalized
// if you want to get a normalized pattern out of it. // if you want to get a normalized pattern out of it.
// Could return a constrained type in order to express that (future work) // Could return a constrained type in order to express that (future work)
fn pat_bindings(pat: @pat, it: block(@pat)) { fn pat_bindings(pat: @pat, it: fn(@pat)) {
alt pat.node { alt pat.node {
pat_ident(_, option::none) { it(pat); } pat_ident(_, option::none) { it(pat); }
pat_ident(_, option::some(sub)) { it(pat); pat_bindings(sub, it); } pat_ident(_, option::some(sub)) { it(pat); pat_bindings(sub, it); }

View file

@ -632,7 +632,7 @@ fn resolve_constr(e: @env, c: @ast::constr, sc: scopes, _v: vt<scopes>) {
fn resolve_import(e: env, defid: ast::def_id, name: ast::ident, fn resolve_import(e: env, defid: ast::def_id, name: ast::ident,
ids: [ast::ident], sp: codemap::span, sc: scopes) { ids: [ast::ident], sp: codemap::span, sc: scopes) {
fn register(e: env, id: node_id, cx: ctxt, sp: codemap::span, fn register(e: env, id: node_id, cx: ctxt, sp: codemap::span,
name: ast::ident, lookup: block(namespace) -> option::t<def>, name: ast::ident, lookup: fn(namespace) -> option::t<def>,
impls: [@_impl]) { impls: [@_impl]) {
let val = lookup(ns_val(ns_any_value)), typ = lookup(ns_type), let val = lookup(ns_val(ns_any_value)), typ = lookup(ns_type),
md = lookup(ns_module); md = lookup(ns_module);
@ -1712,7 +1712,7 @@ fn add_name(ch: checker, sp: span, name: ident) {
fn ident_id(&&i: ident) -> ident { ret i; } fn ident_id(&&i: ident) -> ident { ret i; }
fn ensure_unique<T>(e: env, sp: span, elts: [T], id: block(T) -> ident, fn ensure_unique<T>(e: env, sp: span, elts: [T], id: fn(T) -> ident,
kind: str) { kind: str) {
let ch = checker(e, kind); let ch = checker(e, kind);
for elt: T in elts { add_name(ch, sp, id(elt)); } for elt: T in elts { add_name(ch, sp, id(elt)); }

View file

@ -3233,8 +3233,8 @@ fn invoke_full(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
fn invoke_(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef], fn invoke_(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
to_zero: [{v: ValueRef, t: ty::t}], to_zero: [{v: ValueRef, t: ty::t}],
to_revoke: [{v: ValueRef, t: ty::t}], to_revoke: [{v: ValueRef, t: ty::t}],
invoker: block(@block_ctxt, ValueRef, [ValueRef], invoker: fn(@block_ctxt, ValueRef, [ValueRef],
BasicBlockRef, BasicBlockRef)) -> @block_ctxt { BasicBlockRef, BasicBlockRef)) -> @block_ctxt {
// FIXME: May be worth turning this into a plain call when there are no // FIXME: May be worth turning this into a plain call when there are no
// cleanups to run // cleanups to run
if bcx.unreachable { ret bcx; } if bcx.unreachable { ret bcx; }
@ -4106,7 +4106,7 @@ fn trans_fn_cleanups(fcx: @fn_ctxt, cx: @block_ctxt) {
} }
} }
fn block_locals(b: ast::blk, it: block(@ast::local)) { fn block_locals(b: ast::blk, it: fn(@ast::local)) {
for s: @ast::stmt in b.node.stmts { for s: @ast::stmt in b.node.stmts {
alt s.node { alt s.node {
ast::stmt_decl(d, _) { ast::stmt_decl(d, _) {
@ -4423,7 +4423,7 @@ enum self_arg { impl_self(ty::t), no_self, }
fn trans_closure(cx: @local_ctxt, sp: span, decl: ast::fn_decl, fn trans_closure(cx: @local_ctxt, sp: span, decl: ast::fn_decl,
body: ast::blk, llfndecl: ValueRef, body: ast::blk, llfndecl: ValueRef,
ty_self: self_arg, ty_params: [ast::ty_param], ty_self: self_arg, ty_params: [ast::ty_param],
id: ast::node_id, maybe_load_env: block(@fn_ctxt)) { id: ast::node_id, maybe_load_env: fn(@fn_ctxt)) {
set_uwtable(llfndecl); set_uwtable(llfndecl);
// Set up arguments to the function. // Set up arguments to the function.

View file

@ -57,7 +57,7 @@ import shape::{size_of};
// closure is allocated in the task heap and is reference counted. // closure is allocated in the task heap and is reference counted.
// For a block, the closure is allocated on the stack. Note that in // For a block, the closure is allocated on the stack. Note that in
// all cases we allocate space for a ref count just to make our lives // all cases we allocate space for a ref count just to make our lives
// easier when upcasting to block(T)->U, in the shape code, and so // easier when upcasting to fn(T)->U, in the shape code, and so
// forth. // forth.
// //
// ## Opaque Closures ## // ## Opaque Closures ##
@ -637,7 +637,7 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
fn make_null_test( fn make_null_test(
in_bcx: @block_ctxt, in_bcx: @block_ctxt,
ptr: ValueRef, ptr: ValueRef,
blk: block(@block_ctxt) -> @block_ctxt) blk: fn(@block_ctxt) -> @block_ctxt)
-> @block_ctxt { -> @block_ctxt {
let not_null_bcx = new_sub_block_ctxt(in_bcx, "not null"); let not_null_bcx = new_sub_block_ctxt(in_bcx, "not null");
let next_bcx = new_sub_block_ctxt(in_bcx, "next"); let next_bcx = new_sub_block_ctxt(in_bcx, "next");

View file

@ -157,7 +157,7 @@ fn trans_vtable(ccx: @crate_ctxt, id: ast::node_id, name: str,
} }
fn trans_wrapper(ccx: @crate_ctxt, pt: [ast::ident], llfty: TypeRef, fn trans_wrapper(ccx: @crate_ctxt, pt: [ast::ident], llfty: TypeRef,
fill: block(ValueRef, @block_ctxt) -> @block_ctxt) fill: fn(ValueRef, @block_ctxt) -> @block_ctxt)
-> ValueRef { -> ValueRef {
let lcx = @{path: pt, module_path: [], ccx: ccx}; let lcx = @{path: pt, module_path: [], ccx: ccx};
let name = link::mangle_internal_name_by_path(ccx, pt); let name = link::mangle_internal_name_by_path(ccx, pt);

View file

@ -258,7 +258,7 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhs: ValueRef,
type val_and_ty_fn = fn@(@block_ctxt, ValueRef, ty::t) -> result; type val_and_ty_fn = fn@(@block_ctxt, ValueRef, ty::t) -> result;
type iter_vec_block = block(@block_ctxt, ValueRef, ty::t) -> @block_ctxt; type iter_vec_block = fn(@block_ctxt, ValueRef, ty::t) -> @block_ctxt;
fn iter_vec_raw(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t, fn iter_vec_raw(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t,
fill: ValueRef, f: iter_vec_block) -> @block_ctxt { fill: ValueRef, f: iter_vec_block) -> @block_ctxt {

View file

@ -968,7 +968,7 @@ fn non_init_constraint_mentions(_fcx: fn_ctxt, c: norm_constraint, v: node_id)
} }
fn args_mention<T>(args: [@constr_arg_use], fn args_mention<T>(args: [@constr_arg_use],
q: block([T], node_id) -> bool, q: fn([T], node_id) -> bool,
s: [T]) -> bool { s: [T]) -> bool {
/* /*
FIXME FIXME

View file

@ -1083,7 +1083,7 @@ fn type_is_native(cx: ctxt, ty: t) -> bool {
alt struct(cx, ty) { ty_native(_) { ret true; } _ { ret false; } } alt struct(cx, ty) { ty_native(_) { ret true; } _ { ret false; } }
} }
fn type_structurally_contains(cx: ctxt, ty: t, test: block(sty) -> bool) -> fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) ->
bool { bool {
let sty = struct(cx, ty); let sty = struct(cx, ty);
if test(sty) { ret true; } if test(sty) { ret true; }
@ -1420,7 +1420,7 @@ fn hash_type_structure(st: sty) -> uint {
fn hash_raw_ty(&&rt: @raw_t) -> uint { ret rt.hash; } fn hash_raw_ty(&&rt: @raw_t) -> uint { ret rt.hash; }
fn arg_eq<T>(eq: block(T, T) -> bool, fn arg_eq<T>(eq: fn(T, T) -> bool,
a: @sp_constr_arg<T>, a: @sp_constr_arg<T>,
b: @sp_constr_arg<T>) b: @sp_constr_arg<T>)
-> bool { -> bool {
@ -1439,7 +1439,7 @@ fn arg_eq<T>(eq: block(T, T) -> bool,
} }
} }
fn args_eq<T>(eq: block(T, T) -> bool, fn args_eq<T>(eq: fn(T, T) -> bool,
a: [@sp_constr_arg<T>], a: [@sp_constr_arg<T>],
b: [@sp_constr_arg<T>]) -> bool { b: [@sp_constr_arg<T>]) -> bool {
let i: uint = 0u; let i: uint = 0u;
@ -1930,7 +1930,6 @@ mod unify {
fn sub_proto(p_sub: ast::proto, p_sup: ast::proto) -> bool { fn sub_proto(p_sub: ast::proto, p_sup: ast::proto) -> bool {
ret alt (p_sub, p_sup) { ret alt (p_sub, p_sup) {
(_, ast::proto_any) { true } (_, ast::proto_any) { true }
(_, ast::proto_block) { true } /* NDM temporary */
(ast::proto_bare, _) { true } (ast::proto_bare, _) { true }
// Equal prototypes are always subprotos: // Equal prototypes are always subprotos:
@ -2083,7 +2082,7 @@ mod unify {
} }
fn unify_tps(cx: @ctxt, expected_tps: [t], actual_tps: [t], fn unify_tps(cx: @ctxt, expected_tps: [t], actual_tps: [t],
variance: variance, finish: block([t]) -> result) -> result { variance: variance, finish: fn([t]) -> result) -> result {
let result_tps = [], i = 0u; let result_tps = [], i = 0u;
for exp in expected_tps { for exp in expected_tps {
let act = actual_tps[i]; let act = actual_tps[i];

View file

@ -241,7 +241,7 @@ fn follow_for_trans(cx: ext_ctxt, mmaybe: option::t<arb_depth<matchable>>,
} }
/* helper for transcribe_exprs: what vars from `b` occur in `e`? */ /* helper for transcribe_exprs: what vars from `b` occur in `e`? */
fn free_vars(b: bindings, e: @expr, it: block(ident)) { fn free_vars(b: bindings, e: @expr, it: fn(ident)) {
let idents: hashmap<ident, ()> = new_str_hash::<()>(); let idents: hashmap<ident, ()> = new_str_hash::<()>();
fn mark_ident(&&i: ident, _fld: ast_fold, b: bindings, fn mark_ident(&&i: ident, _fld: ast_fold, b: bindings,
idents: hashmap<ident, ()>) -> ident { idents: hashmap<ident, ()>) -> ident {
@ -536,7 +536,7 @@ fn block_to_ident(blk: blk_) -> option::t<ident> {
fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) { fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
fn select_pt_1(cx: ext_ctxt, m: matchable, fn select_pt_1(cx: ext_ctxt, m: matchable,
fn_m: block(ast::mac) -> match_result) -> match_result { fn_m: fn(ast::mac) -> match_result) -> match_result {
ret alt m { ret alt m {
match_expr(e) { match_expr(e) {
alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } } alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } }

View file

@ -149,7 +149,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
for word in ["mod", "if", "else", "while", "do", "alt", "for", "break", for word in ["mod", "if", "else", "while", "do", "alt", "for", "break",
"cont", "ret", "be", "fail", "type", "resource", "check", "cont", "ret", "be", "fail", "type", "resource", "check",
"assert", "claim", "native", "fn", "pure", "assert", "claim", "native", "fn", "pure",
"unsafe", "block", "import", "export", "let", "const", "unsafe", "import", "export", "let", "const",
"log", "copy", "sendfn", "impl", "iface", "enum"] { "log", "copy", "sendfn", "impl", "iface", "enum"] {
words.insert(word, ()); words.insert(word, ());
} }
@ -366,7 +366,7 @@ fn parse_constr_in_type(p: parser) -> @ast::ty_constr {
} }
fn parse_constrs<T: copy>(pser: block(parser) -> @ast::constr_general<T>, fn parse_constrs<T: copy>(pser: fn(parser) -> @ast::constr_general<T>,
p: parser) -> p: parser) ->
[@ast::constr_general<T>] { [@ast::constr_general<T>] {
let constrs: [@ast::constr_general<T>] = []; let constrs: [@ast::constr_general<T>] = [];
@ -504,9 +504,6 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
_ { /* fallthrough */ } _ { /* fallthrough */ }
} }
t = parse_ty_fn(proto, p); t = parse_ty_fn(proto, p);
} else if eat_word(p, "block") {
//p.warn("block is deprecated, use fn& or fn");
t = parse_ty_fn(ast::proto_block, p);
} else if eat_word(p, "native") { } else if eat_word(p, "native") {
expect_word(p, "fn"); expect_word(p, "fn");
t = parse_ty_fn(ast::proto_bare, p); t = parse_ty_fn(ast::proto_bare, p);
@ -545,7 +542,7 @@ fn parse_fn_block_arg(p: parser) -> ast::arg {
} }
fn parse_seq_to_before_gt<T: copy>(sep: option::t<token::token>, fn parse_seq_to_before_gt<T: copy>(sep: option::t<token::token>,
f: block(parser) -> T, f: fn(parser) -> T,
p: parser) -> [T] { p: parser) -> [T] {
let first = true; let first = true;
let v = []; let v = [];
@ -562,7 +559,7 @@ fn parse_seq_to_before_gt<T: copy>(sep: option::t<token::token>,
} }
fn parse_seq_to_gt<T: copy>(sep: option::t<token::token>, fn parse_seq_to_gt<T: copy>(sep: option::t<token::token>,
f: block(parser) -> T, p: parser) -> [T] { f: fn(parser) -> T, p: parser) -> [T] {
let v = parse_seq_to_before_gt(sep, f, p); let v = parse_seq_to_before_gt(sep, f, p);
expect_gt(p); expect_gt(p);
@ -570,7 +567,7 @@ fn parse_seq_to_gt<T: copy>(sep: option::t<token::token>,
} }
fn parse_seq_lt_gt<T: copy>(sep: option::t<token::token>, fn parse_seq_lt_gt<T: copy>(sep: option::t<token::token>,
f: block(parser) -> T, f: fn(parser) -> T,
p: parser) -> spanned<[T]> { p: parser) -> spanned<[T]> {
let lo = p.span.lo; let lo = p.span.lo;
expect(p, token::LT); expect(p, token::LT);
@ -581,7 +578,7 @@ fn parse_seq_lt_gt<T: copy>(sep: option::t<token::token>,
} }
fn parse_seq_to_end<T: copy>(ket: token::token, sep: seq_sep, fn parse_seq_to_end<T: copy>(ket: token::token, sep: seq_sep,
f: block(parser) -> T, p: parser) -> [T] { f: fn(parser) -> T, p: parser) -> [T] {
let val = parse_seq_to_before_end(ket, sep, f, p); let val = parse_seq_to_before_end(ket, sep, f, p);
p.bump(); p.bump();
ret val; ret val;
@ -604,7 +601,7 @@ fn seq_sep_none() -> seq_sep {
fn parse_seq_to_before_end<T: copy>(ket: token::token, fn parse_seq_to_before_end<T: copy>(ket: token::token,
sep: seq_sep, sep: seq_sep,
f: block(parser) -> T, p: parser) -> [T] { f: fn(parser) -> T, p: parser) -> [T] {
let first: bool = true; let first: bool = true;
let v: [T] = []; let v: [T] = [];
while p.token != ket { while p.token != ket {
@ -620,7 +617,7 @@ fn parse_seq_to_before_end<T: copy>(ket: token::token,
fn parse_seq<T: copy>(bra: token::token, ket: token::token, fn parse_seq<T: copy>(bra: token::token, ket: token::token,
sep: seq_sep, f: block(parser) -> T, sep: seq_sep, f: fn(parser) -> T,
p: parser) -> spanned<[T]> { p: parser) -> spanned<[T]> {
let lo = p.span.lo; let lo = p.span.lo;
expect(p, bra); expect(p, bra);
@ -813,9 +810,6 @@ fn parse_bottom_expr(p: parser) -> pexpr {
_ { /* fallthrough */ } _ { /* fallthrough */ }
} }
ret pexpr(parse_fn_expr(p, proto)); ret pexpr(parse_fn_expr(p, proto));
} else if eat_word(p, "block") {
p.warn("block is deprecated, use fn& or fn");
ret pexpr(parse_fn_expr(p, ast::proto_block));
} else if eat_word(p, "unchecked") { } else if eat_word(p, "unchecked") {
ret pexpr(parse_block_expr(p, lo, ast::unchecked_blk)); ret pexpr(parse_block_expr(p, lo, ast::unchecked_blk));
} else if eat_word(p, "unsafe") { } else if eat_word(p, "unsafe") {

View file

@ -210,7 +210,7 @@ fn synth_comment(s: ps, text: str) {
word(s.s, "*/"); word(s.s, "*/");
} }
fn commasep<IN>(s: ps, b: breaks, elts: [IN], op: block(ps, IN)) { fn commasep<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN)) {
box(s, 0u, b); box(s, 0u, b);
let first = true; let first = true;
for elt: IN in elts { for elt: IN in elts {
@ -221,8 +221,8 @@ fn commasep<IN>(s: ps, b: breaks, elts: [IN], op: block(ps, IN)) {
} }
fn commasep_cmnt<IN>(s: ps, b: breaks, elts: [IN], op: block(ps, IN), fn commasep_cmnt<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN),
get_span: block(IN) -> codemap::span) { get_span: fn(IN) -> codemap::span) {
box(s, 0u, b); box(s, 0u, b);
let len = vec::len::<IN>(elts); let len = vec::len::<IN>(elts);
let i = 0u; let i = 0u;

View file

@ -18,7 +18,7 @@ export relative_target_lib_path;
export get_cargo_root; export get_cargo_root;
export libdir; export libdir;
type pick<T> = block(path: fs::path) -> option::t<T>; type pick<T> = fn(path: fs::path) -> option::t<T>;
fn pick_file(file: fs::path, path: fs::path) -> option::t<fs::path> { fn pick_file(file: fs::path, path: fs::path) -> option::t<fs::path> {
if fs::basename(path) == file { option::some(path) } if fs::basename(path) == file { option::some(path) }

View file

@ -63,7 +63,7 @@ fn is_test_ignored(config: config, testfile: str) -> bool {
} }
} }
fn iter_header(testfile: str, it: block(str)) { fn iter_header(testfile: str, it: fn(str)) {
let rdr = result::get(io::file_reader(testfile)); let rdr = result::get(io::file_reader(testfile));
while !rdr.eof() { while !rdr.eof() {
let ln = rdr.read_line(); let ln = rdr.read_line();

View file

@ -215,7 +215,7 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty, tm: test_mode
*crate2 *crate2
} }
fn under(n: uint, it: block(uint)) { fn under(n: uint, it: fn(uint)) {
let i: uint = 0u; let i: uint = 0u;
while i < n { it(i); i += 1u; } while i < n { it(i); i += 1u; }
} }

View file

@ -75,7 +75,7 @@ pure fn to_str(v: t) -> str { if v { "true" } else { "false" } }
brief = "Iterates over all truth values by passing them to `blk` \ brief = "Iterates over all truth values by passing them to `blk` \
in an unspecified order" in an unspecified order"
)] )]
fn all_values(blk: block(v: t)) { fn all_values(blk: fn(v: t)) {
blk(true); blk(true);
blk(false); blk(false);
} }

View file

@ -29,7 +29,7 @@ If `value` is left(T) then `f_left` is applied to its contents, if
the result is returned. the result is returned.
*/ */
fn either<T, U, fn either<T, U,
V>(f_left: block(T) -> V, f_right: block(U) -> V, value: t<T, U>) -> V>(f_left: fn(T) -> V, f_right: fn(U) -> V, value: t<T, U>) ->
V { V {
alt value { left(l) { f_left(l) } right(r) { f_right(r) } } alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
} }

View file

@ -84,7 +84,7 @@ Function: range
Iterate over the range [`lo`..`hi`) Iterate over the range [`lo`..`hi`)
*/ */
fn range(lo: int, hi: int, it: block(int)) { fn range(lo: int, hi: int, it: fn(int)) {
let i = lo; let i = lo;
while i < hi { it(i); i += 1; } while i < hi { it(i); i += 1; }
} }

View file

@ -36,7 +36,7 @@ pure fn get<T: copy>(opt: t<T>) -> T {
/* /*
*/ */
fn map<T, U: copy>(opt: t<T>, f: block(T) -> U) -> t<U> { fn map<T, U: copy>(opt: t<T>, f: fn(T) -> U) -> t<U> {
alt opt { some(x) { some(f(x)) } none { none } } 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 Applies a function to the contained value or returns a default
*/ */
fn maybe<T, U: copy>(def: U, opt: t<T>, f: block(T) -> U) -> U { fn maybe<T, U: copy>(def: U, opt: t<T>, f: fn(T) -> U) -> U {
alt opt { none { def } some(t) { f(t) } } alt opt { none { def } some(t) { f(t) } }
} }
@ -80,7 +80,7 @@ Function: may
Performs an operation on the contained value or does nothing Performs an operation on the contained value or does nothing
*/ */
fn may<T>(opt: t<T>, f: block(T)) { fn may<T>(opt: t<T>, f: fn(T)) {
alt opt { none {/* nothing */ } some(t) { f(t); } } alt opt { none {/* nothing */ } some(t) { f(t); } }
} }

View file

@ -110,7 +110,7 @@ Example:
> }) > })
*/ */
fn chain<T, U: copy, V: copy>(res: t<T, V>, op: block(T) -> t<U, V>) fn chain<T, U: copy, V: copy>(res: t<T, V>, op: fn(T) -> t<U, V>)
-> t<U, V> { -> t<U, V> {
alt res { alt res {
ok(t) { op(t) } ok(t) { op(t) }

View file

@ -347,7 +347,7 @@ Function: iter_chars
Iterate over the characters in a string Iterate over the characters in a string
*/ */
fn iter_chars(s: str, it: block(char)) { fn iter_chars(s: str, it: fn(char)) {
let pos = 0u, len = byte_len(s); let pos = 0u, len = byte_len(s);
while (pos < len) { while (pos < len) {
let {ch, next} = char_range_at(s, pos); let {ch, next} = char_range_at(s, pos);
@ -371,7 +371,7 @@ Returns:
`true` If execution proceeded correctly, `false` if it was interrupted, `true` If execution proceeded correctly, `false` if it was interrupted,
that is if `it` returned `false` at any point. that is if `it` returned `false` at any point.
*/ */
fn loop_chars(s: str, it: block(char) -> bool) -> bool{ fn loop_chars(s: str, it: fn(char) -> bool) -> bool{
ret loop_chars_sub(s, 0u, byte_len(s), it); ret loop_chars_sub(s, 0u, byte_len(s), it);
} }
@ -398,7 +398,7 @@ Safety note:
represent valid positions inside `s` represent valid positions inside `s`
*/ */
fn loop_chars_sub(s: str, byte_offset: uint, byte_len: uint, fn loop_chars_sub(s: str, byte_offset: uint, byte_len: uint,
it: block(char) -> bool) -> bool { it: fn(char) -> bool) -> bool {
let i = byte_offset; let i = byte_offset;
let result = true; let result = true;
while i < byte_len { while i < byte_len {
@ -1061,7 +1061,7 @@ Example:
> let s = str::as_buf("PATH", { |path_buf| libc::getenv(path_buf) }); > let s = str::as_buf("PATH", { |path_buf| libc::getenv(path_buf) });
*/ */
fn as_buf<T>(s: str, f: block(sbuf) -> T) -> T unsafe { fn as_buf<T>(s: str, f: fn(sbuf) -> T) -> T unsafe {
let buf = buf(s); f(buf) let buf = buf(s); f(buf)
} }

View file

@ -54,7 +54,7 @@ Function: range
Iterate over the range [`lo`..`hi`) Iterate over the range [`lo`..`hi`)
*/ */
fn range(lo: u32, hi: u32, it: block(u32)) { fn range(lo: u32, hi: u32, it: fn(u32)) {
let i = lo; let i = lo;
while i < hi { it(i); i += 1u32; } while i < hi { it(i); i += 1u32; }
} }

View file

@ -54,7 +54,7 @@ Function: range
Iterate over the range [`lo`..`hi`) Iterate over the range [`lo`..`hi`)
*/ */
fn range(lo: u64, hi: u64, it: block(u64)) { fn range(lo: u64, hi: u64, it: fn(u64)) {
let i = lo; let i = lo;
while i < hi { it(i); i += 1u64; } while i < hi { it(i); i += 1u64; }
} }

View file

@ -54,7 +54,7 @@ Function: range
Iterate over the range [`lo`..`hi`) Iterate over the range [`lo`..`hi`)
*/ */
fn range(lo: u8, hi: u8, it: block(u8)) { fn range(lo: u8, hi: u8, it: fn(u8)) {
let i = lo; let i = lo;
while i < hi { it(i); i += 1u8; } while i < hi { it(i); i += 1u8; }
} }

View file

@ -115,7 +115,7 @@ Function: range
Iterate over the range [`lo`..`hi`) Iterate over the range [`lo`..`hi`)
*/ */
fn range(lo: uint, hi: uint, it: block(uint)) { fn range(lo: uint, hi: uint, it: fn(uint)) {
let i = lo; let i = lo;
while i < hi { it(i); i += 1u; } while i < hi { it(i); i += 1u; }
} }
@ -136,7 +136,7 @@ Returns:
`true` If execution proceeded correctly, `false` if it was interrupted, `true` If execution proceeded correctly, `false` if it was interrupted,
that is if `it` returned `false` at any point. that is if `it` returned `false` at any point.
*/ */
fn loop(lo: uint, hi: uint, it: block(uint) -> bool) -> bool { fn loop(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool {
let i = lo; let i = lo;
while i < hi { while i < hi {
if (!it(i)) { ret false; } if (!it(i)) { ret false; }

View file

@ -26,7 +26,7 @@ Type: init_op
A function used to initialize the elements of a vector. A function used to initialize the elements of a vector.
*/ */
type init_op<T> = block(uint) -> T; type init_op<T> = fn(uint) -> T;
/* /*
@ -402,7 +402,7 @@ Function: map
Apply a function to each element of a vector and return the results Apply a function to each element of a vector and return the results
*/ */
fn map<T, U>(v: [T], f: block(T) -> U) -> [U] { fn map<T, U>(v: [T], f: fn(T) -> U) -> [U] {
let result = []; let result = [];
reserve(result, len(v)); reserve(result, len(v));
for elem: T in v { result += [f(elem)]; } for elem: T in v { result += [f(elem)]; }
@ -414,7 +414,7 @@ Function: map_mut
Apply a function to each element of a mutable vector and return the results Apply a function to each element of a mutable vector and return the results
*/ */
fn map_mut<T: copy, U>(v: [const T], f: block(T) -> U) -> [U] { fn map_mut<T: copy, U>(v: [const T], f: fn(T) -> U) -> [U] {
let result = []; let result = [];
reserve(result, len(v)); reserve(result, len(v));
for elem: T in v { for elem: T in v {
@ -429,7 +429,7 @@ Function: map2
Apply a function to each pair of elements and return the results Apply a function to each pair of elements and return the results
*/ */
fn map2<T: copy, U: copy, V>(v0: [T], v1: [U], f: block(T, U) -> V) -> [V] { fn map2<T: copy, U: copy, V>(v0: [T], v1: [U], f: fn(T, U) -> V) -> [V] {
let v0_len = len(v0); let v0_len = len(v0);
if v0_len != len(v1) { fail; } if v0_len != len(v1) { fail; }
let u: [V] = []; let u: [V] = [];
@ -446,7 +446,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 If function `f` returns `none` then that element is excluded from
the resulting vector. the resulting vector.
*/ */
fn filter_map<T: copy, U: copy>(v: [const T], f: block(T) -> option::t<U>) fn filter_map<T: copy, U: copy>(v: [const T], f: fn(T) -> option::t<U>)
-> [U] { -> [U] {
let result = []; let result = [];
for elem: T in v { for elem: T in v {
@ -467,7 +467,7 @@ holds.
Apply function `f` to each element of `v` and return a vector containing Apply function `f` to each element of `v` and return a vector containing
only those elements for which `f` returned true. only those elements for which `f` returned true.
*/ */
fn filter<T: copy>(v: [T], f: block(T) -> bool) -> [T] { fn filter<T: copy>(v: [T], f: fn(T) -> bool) -> [T] {
let result = []; let result = [];
for elem: T in v { for elem: T in v {
if f(elem) { result += [elem]; } if f(elem) { result += [elem]; }
@ -492,7 +492,7 @@ Function: foldl
Reduce a vector from left to right Reduce a vector from left to right
*/ */
fn foldl<T: copy, U>(z: T, v: [const U], p: block(T, U) -> T) -> T { fn foldl<T: copy, U>(z: T, v: [const U], p: fn(T, U) -> T) -> T {
let accum = z; let accum = z;
iter(v) { |elt| iter(v) { |elt|
accum = p(accum, elt); accum = p(accum, elt);
@ -505,7 +505,7 @@ Function: foldr
Reduce a vector from right to left Reduce a vector from right to left
*/ */
fn foldr<T, U: copy>(v: [const T], z: U, p: block(T, U) -> U) -> U { fn foldr<T, U: copy>(v: [const T], z: U, p: fn(T, U) -> U) -> U {
let accum = z; let accum = z;
riter(v) { |elt| riter(v) { |elt|
accum = p(elt, accum); accum = p(elt, accum);
@ -520,7 +520,7 @@ Return true if a predicate matches any elements
If the vector contains no elements then false is returned. If the vector contains no elements then false is returned.
*/ */
fn any<T>(v: [T], f: block(T) -> bool) -> bool { fn any<T>(v: [T], f: fn(T) -> bool) -> bool {
for elem: T in v { if f(elem) { ret true; } } for elem: T in v { if f(elem) { ret true; } }
ret false; ret false;
} }
@ -532,7 +532,7 @@ Return true if a predicate matches any elements in both vectors.
If the vectors contains no elements then false is returned. If the vectors contains no elements then false is returned.
*/ */
fn any2<T, U>(v0: [T], v1: [U], f: block(T, U) -> bool) -> bool { fn any2<T, U>(v0: [T], v1: [U], f: fn(T, U) -> bool) -> bool {
let v0_len = len(v0); let v0_len = len(v0);
let v1_len = len(v1); let v1_len = len(v1);
let i = 0u; let i = 0u;
@ -550,7 +550,7 @@ Return true if a predicate matches all elements
If the vector contains no elements then true is returned. If the vector contains no elements then true is returned.
*/ */
fn all<T>(v: [T], f: block(T) -> bool) -> bool { fn all<T>(v: [T], f: fn(T) -> bool) -> bool {
for elem: T in v { if !f(elem) { ret false; } } for elem: T in v { if !f(elem) { ret false; } }
ret true; ret true;
} }
@ -562,7 +562,7 @@ Return true if a predicate matches all elements in both vectors.
If the vectors are not the same size then false is returned. If the vectors are not the same size then false is returned.
*/ */
fn all2<T, U>(v0: [T], v1: [U], f: block(T, U) -> bool) -> bool { fn all2<T, U>(v0: [T], v1: [U], f: fn(T, U) -> bool) -> bool {
let v0_len = len(v0); let v0_len = len(v0);
if v0_len != len(v1) { ret false; } if v0_len != len(v1) { ret false; }
let i = 0u; let i = 0u;
@ -600,7 +600,7 @@ Apply function `f` to each element of `v`, starting from the first.
When function `f` returns true then an option containing the element When function `f` returns true then an option containing the element
is returned. If `f` matches no elements then none is returned. is returned. If `f` matches no elements then none is returned.
*/ */
fn find<T: copy>(v: [T], f: block(T) -> bool) -> option::t<T> { fn find<T: copy>(v: [T], f: fn(T) -> bool) -> option::t<T> {
for elt: T in v { if f(elt) { ret some(elt); } } for elt: T in v { if f(elt) { ret some(elt); } }
ret none; ret none;
} }
@ -626,7 +626,7 @@ Function: position_pred
Find the first index for which the value matches some predicate Find the first index for which the value matches some predicate
*/ */
fn position_pred<T>(v: [T], f: block(T) -> bool) -> option::t<uint> { fn position_pred<T>(v: [T], f: fn(T) -> bool) -> option::t<uint> {
let i: uint = 0u; let i: uint = 0u;
while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; } while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
ret none; ret none;
@ -747,7 +747,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the
element's value. element's value.
*/ */
fn iter<T>(v: [const T], f: block(T)) { fn iter<T>(v: [const T], f: fn(T)) {
iteri(v) { |_i, v| f(v) } iteri(v) { |_i, v| f(v) }
} }
@ -757,7 +757,7 @@ Function: iter2
Iterates over two vectors in parallel Iterates over two vectors in parallel
*/ */
fn iter2<U, T>(v: [U], v2: [T], f: block(U, T)) { fn iter2<U, T>(v: [U], v2: [T], f: fn(U, T)) {
let i = 0; let i = 0;
for elt in v { f(elt, v2[i]); i += 1; } for elt in v { f(elt, v2[i]); i += 1; }
} }
@ -770,7 +770,7 @@ Iterates over a vector's elements and indexes
Iterates over vector `v` and, for each element, calls function `f` with the Iterates over vector `v` and, for each element, calls function `f` with the
element's value and index. element's value and index.
*/ */
fn iteri<T>(v: [const T], f: block(uint, T)) { fn iteri<T>(v: [const T], f: fn(uint, T)) {
let i = 0u, l = len(v); let i = 0u, l = len(v);
while i < l { f(i, v[i]); i += 1u; } while i < l { f(i, v[i]); i += 1u; }
} }
@ -784,7 +784,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the
element's value. element's value.
*/ */
fn riter<T>(v: [const T], f: block(T)) { fn riter<T>(v: [const T], f: fn(T)) {
riteri(v) { |_i, v| f(v) } riteri(v) { |_i, v| f(v) }
} }
@ -796,7 +796,7 @@ Iterates over a vector's elements and indexes in reverse
Iterates over vector `v` and, for each element, calls function `f` with the Iterates over vector `v` and, for each element, calls function `f` with the
element's value and index. element's value and index.
*/ */
fn riteri<T>(v: [const T], f: block(uint, T)) { fn riteri<T>(v: [const T], f: fn(uint, T)) {
let i = len(v); let i = len(v);
while 0u < i { while 0u < i {
i -= 1u; i -= 1u;
@ -814,7 +814,7 @@ is sorted then the permutations are lexicographically sorted).
The total number of permutations produced is `len(v)!`. If `v` contains The total number of permutations produced is `len(v)!`. If `v` contains
repeated elements, then some permutations are repeated. repeated elements, then some permutations are repeated.
*/ */
fn permute<T: copy>(v: [const T], put: block([T])) { fn permute<T: copy>(v: [const T], put: fn([T])) {
let ln = len(v); let ln = len(v);
if ln == 0u { if ln == 0u {
put([]); put([]);

View file

@ -53,7 +53,7 @@ fn create(nbits: uint, init: bool) -> t {
ret @{storage: storage, nbits: nbits}; ret @{storage: storage, nbits: nbits};
} }
fn process(v0: t, v1: t, op: block(uint, uint) -> uint) -> bool { fn process(v0: t, v1: t, op: fn(uint, uint) -> uint) -> bool {
let len = vec::len(v1.storage); let len = vec::len(v1.storage);
assert (vec::len(v0.storage) == len); assert (vec::len(v0.storage) == len);
assert (v0.nbits == v1.nbits); assert (v0.nbits == v1.nbits);

View file

@ -73,7 +73,7 @@ fn get_doc(d: doc, tg: uint) -> doc {
} }
} }
fn docs(d: doc, it: block(uint, doc)) { fn docs(d: doc, it: fn(uint, doc)) {
let pos = d.start; let pos = d.start;
while pos < d.end { while pos < d.end {
let elt_tag = vint_at(*d.data, pos); let elt_tag = vint_at(*d.data, pos);
@ -83,7 +83,7 @@ fn docs(d: doc, it: block(uint, doc)) {
} }
} }
fn tagged_docs(d: doc, tg: uint, it: block(doc)) { fn tagged_docs(d: doc, tg: uint, it: fn(doc)) {
let pos = d.start; let pos = d.start;
while pos < d.end { while pos < d.end {
let elt_tag = vint_at(*d.data, pos); let elt_tag = vint_at(*d.data, pos);

View file

@ -195,7 +195,7 @@ Function: all_values
Iterates over all truth values by passing them to `blk` Iterates over all truth values by passing them to `blk`
in an unspecified order in an unspecified order
*/ */
fn all_values(blk: block(v: t)) { fn all_values(blk: fn(v: t)) {
blk(both); blk(both);
blk(four::true); blk(four::true);
blk(four::false); blk(four::false);

View file

@ -84,7 +84,7 @@ Function: traverse
Visit all pairs in the map in order. Visit all pairs in the map in order.
*/ */
fn traverse<K, V: copy>(m: treemap<K, V>, f: block(K, V)) { fn traverse<K, V: copy>(m: treemap<K, V>, f: fn(K, V)) {
alt *m { alt *m {
empty { } empty { }
node(@k, @v, _, _) { node(@k, @v, _, _) {

View file

@ -529,7 +529,7 @@ mod fsync {
// fsync file after executing blk // fsync file after executing blk
// FIXME find better way to create resources within lifetime of outer res // FIXME find better way to create resources within lifetime of outer res
fn FILE_res_sync(&&file: FILE_res, opt_level: option::t<level>, fn FILE_res_sync(&&file: FILE_res, opt_level: option::t<level>,
blk: block(&&res<os::libc::FILE>)) { blk: fn(&&res<os::libc::FILE>)) {
blk(res({ blk(res({
val: *file, opt_level: opt_level, val: *file, opt_level: opt_level,
fsync_fn: fn@(&&file: os::libc::FILE, l: level) -> int { fsync_fn: fn@(&&file: os::libc::FILE, l: level) -> int {
@ -540,7 +540,7 @@ mod fsync {
// fsync fd after executing blk // fsync fd after executing blk
fn fd_res_sync(&&fd: fd_res, opt_level: option::t<level>, fn fd_res_sync(&&fd: fd_res, opt_level: option::t<level>,
blk: block(&&res<fd_t>)) { blk: fn(&&res<fd_t>)) {
blk(res({ blk(res({
val: *fd, opt_level: opt_level, val: *fd, opt_level: opt_level,
fsync_fn: fn@(&&fd: fd_t, l: level) -> int { fsync_fn: fn@(&&fd: fd_t, l: level) -> int {
@ -553,7 +553,7 @@ mod fsync {
iface t { fn fsync(l: level) -> int; } iface t { fn fsync(l: level) -> int; }
// Call o.fsync after executing blk // Call o.fsync after executing blk
fn obj_sync(&&o: t, opt_level: option::t<level>, blk: block(&&res<t>)) { fn obj_sync(&&o: t, opt_level: option::t<level>, blk: fn(&&res<t>)) {
blk(res({ blk(res({
val: o, opt_level: opt_level, val: o, opt_level: opt_level,
fsync_fn: fn@(&&o: t, l: level) -> int { ret o.fsync(l); } fsync_fn: fn@(&&o: t, l: level) -> int { ret o.fsync(l); }

View file

@ -46,7 +46,7 @@ ls - The list to fold
z - The initial value z - The initial value
f - The function to apply f - The function to apply
*/ */
fn foldl<T: copy, U>(ls: list<U>, z: T, f: block(T, U) -> T) -> T { fn foldl<T: copy, U>(ls: list<U>, z: T, f: fn(T, U) -> T) -> T {
let accum: T = z; let accum: T = z;
iter(ls) {|elt| accum = f(accum, elt);} iter(ls) {|elt| accum = f(accum, elt);}
accum accum
@ -61,7 +61,7 @@ Apply function `f` to each element of `v`, starting from the first.
When function `f` returns true then an option containing the element When function `f` returns true then an option containing the element
is returned. If `f` matches no elements then none is returned. is returned. If `f` matches no elements then none is returned.
*/ */
fn find<T: copy, U: copy>(ls: list<T>, f: block(T) -> option::t<U>) fn find<T: copy, U: copy>(ls: list<T>, f: fn(T) -> option::t<U>)
-> option::t<U> { -> option::t<U> {
let ls = ls; let ls = ls;
while true { while true {
@ -164,7 +164,7 @@ Function: iter
Iterate over a list Iterate over a list
*/ */
fn iter<T>(l: list<T>, f: block(T)) { fn iter<T>(l: list<T>, f: fn(T)) {
alt l { alt l {
cons(hd, tl) { cons(hd, tl) {
f(hd); f(hd);

View file

@ -88,17 +88,17 @@ iface map<K: copy, V: copy> {
Iterate over all the key/value pairs in the map Iterate over all the key/value pairs in the map
*/ */
fn items(block(K, V)); fn items(fn(K, V));
/* /*
Method: keys Method: keys
Iterate over all the keys in the map Iterate over all the keys in the map
*/ */
fn keys(block(K)); fn keys(fn(K));
/* /*
Iterate over all the values in the map Iterate over all the values in the map
*/ */
fn values(block(V)); fn values(fn(V));
} }
// FIXME: package this up and export it as a datatype usable for // FIXME: package this up and export it as a datatype usable for
@ -246,7 +246,7 @@ mod chained {
} }
fn foreach_entry<K: copy, V: copy>(chain0: chain<K,V>, fn foreach_entry<K: copy, V: copy>(chain0: chain<K,V>,
blk: block(@entry<K,V>)) { blk: fn(@entry<K,V>)) {
let chain = chain0; let chain = chain0;
while true { while true {
alt chain { alt chain {
@ -261,7 +261,7 @@ mod chained {
} }
fn foreach_chain<K: copy, V: copy>(chains: [const chain<K,V>], fn foreach_chain<K: copy, V: copy>(chains: [const chain<K,V>],
blk: block(@entry<K,V>)) { blk: fn(@entry<K,V>)) {
let i = 0u, n = vec::len(chains); let i = 0u, n = vec::len(chains);
while i < n { while i < n {
foreach_entry(chains[i], blk); foreach_entry(chains[i], blk);
@ -281,7 +281,7 @@ mod chained {
} }
} }
fn items<K: copy, V: copy>(tbl: t<K,V>, blk: block(K,V)) { fn items<K: copy, V: copy>(tbl: t<K,V>, blk: fn(K,V)) {
let tbl_chains = tbl.chains; // Satisfy alias checker. let tbl_chains = tbl.chains; // Satisfy alias checker.
foreach_chain(tbl_chains) { |entry| foreach_chain(tbl_chains) { |entry|
let key = entry.key; let key = entry.key;
@ -310,11 +310,11 @@ mod chained {
fn remove(k: K) -> option::t<V> { remove(self, k) } fn remove(k: K) -> option::t<V> { remove(self, k) }
fn items(blk: block(K, V)) { items(self, blk); } fn items(blk: fn(K, V)) { items(self, blk); }
fn keys(blk: block(K)) { items(self) { |k, _v| blk(k) } } fn keys(blk: fn(K)) { items(self) { |k, _v| blk(k) } }
fn values(blk: block(V)) { items(self) { |_k, v| blk(v) } } fn values(blk: fn(V)) { items(self) { |_k, v| blk(v) } }
} }
fn mk<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) -> map<K,V> { fn mk<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) -> map<K,V> {

View file

@ -81,7 +81,7 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
fn md4_str(msg: [u8]) -> str { fn md4_str(msg: [u8]) -> str {
let {a, b, c, d} = md4(msg); let {a, b, c, d} = md4(msg);
fn app(a: u32, b: u32, c: u32, d: u32, f: block(u32)) { fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
f(a); f(b); f(c); f(d); f(a); f(b); f(c); f(d);
} }
let result = ""; let result = "";

View file

@ -419,7 +419,7 @@ Returns:
`true` If execution proceeded correctly, `false` if it was interrupted, `true` If execution proceeded correctly, `false` if it was interrupted,
that is if `it` returned `false` at any point. that is if `it` returned `false` at any point.
*/ */
fn loop_chars(rope: rope, it: block(char) -> bool) -> bool { fn loop_chars(rope: rope, it: fn(char) -> bool) -> bool {
alt(rope) { alt(rope) {
node::empty { ret true } node::empty { ret true }
node::content(x) { ret node::loop_chars(x, it) } node::content(x) { ret node::loop_chars(x, it) }
@ -435,7 +435,7 @@ Parameters:
rope - A rope to traverse. It may be empty rope - A rope to traverse. It may be empty
it - A block to execute with each consecutive character of the rope. it - A block to execute with each consecutive character of the rope.
*/ */
fn iter_chars(rope: rope, it: block(char)) { fn iter_chars(rope: rope, it: fn(char)) {
loop_chars(rope) {|x| loop_chars(rope) {|x|
it(x); it(x);
ret true ret true
@ -466,7 +466,7 @@ Returns:
`true` If execution proceeded correctly, `false` if it was interrupted, `true` If execution proceeded correctly, `false` if it was interrupted,
that is if `it` returned `false` at any point. that is if `it` returned `false` at any point.
*/ */
fn loop_leaves(rope: rope, it: block(node::leaf) -> bool) -> bool{ fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{
alt(rope) { alt(rope) {
node::empty { ret true } node::empty { ret true }
node::content(x) {ret node::loop_leaves(x, it)} node::content(x) {ret node::loop_leaves(x, it)}
@ -1135,7 +1135,7 @@ mod node {
ret result; ret result;
} }
fn loop_chars(node: @node, it: block(char) -> bool) -> bool { fn loop_chars(node: @node, it: fn(char) -> bool) -> bool {
ret loop_leaves(node, {|leaf| ret loop_leaves(node, {|leaf|
ret str::loop_chars_sub(*leaf.content, ret str::loop_chars_sub(*leaf.content,
leaf.byte_offset, leaf.byte_offset,
@ -1159,7 +1159,7 @@ mod node {
`true` If execution proceeded correctly, `false` if it was interrupted, `true` If execution proceeded correctly, `false` if it was interrupted,
that is if `it` returned `false` at any point. that is if `it` returned `false` at any point.
*/ */
fn loop_leaves(node: @node, it: block(leaf) -> bool) -> bool{ fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool{
let current = node; let current = node;
while true { while true {
alt(*current) { alt(*current) {

View file

@ -110,7 +110,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn get(&&key: uint) -> V { get(self, key) } fn get(&&key: uint) -> V { get(self, key) }
fn find(&&key: uint) -> option::t<V> { find(self, key) } fn find(&&key: uint) -> option::t<V> { find(self, key) }
fn rehash() { fail } fn rehash() { fail }
fn items(it: block(&&uint, V)) { fn items(it: fn(&&uint, V)) {
let idx = 0u; let idx = 0u;
for item in self.v { for item in self.v {
alt item { alt item {
@ -122,14 +122,14 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
idx += 1u; idx += 1u;
} }
} }
fn keys(it: block(&&uint)) { fn keys(it: fn(&&uint)) {
let idx = 0u; let idx = 0u;
for item in self.v { for item in self.v {
if item != none { it(idx); } if item != none { it(idx); }
idx += 1u; idx += 1u;
} }
} }
fn values(it: block(V)) { fn values(it: fn(V)) {
for item in self.v { for item in self.v {
alt item { some(elt) { it(elt); } _ {} } alt item { some(elt) { it(elt); } _ {} }
} }

View file

@ -10,7 +10,7 @@ export quick_sort;
export quick_sort3; export quick_sort3;
/* Type: lteq */ /* Type: lteq */
type lteq<T> = block(T, T) -> bool; type lteq<T> = fn(T, T) -> bool;
/* /*
Function: merge_sort Function: merge_sort

View file

@ -83,7 +83,7 @@ Function: traverse
Visit all pairs in the map in order. Visit all pairs in the map in order.
*/ */
fn traverse<K, V>(m: treemap<K, V>, f: block(K, V)) { fn traverse<K, V>(m: treemap<K, V>, f: fn(K, V)) {
alt *m { alt *m {
empty { } empty { }
node(k, v, _, _) { node(k, v, _, _) {

View file

@ -164,7 +164,7 @@ Function: all_values
Iterates over all truth values by passing them to `blk` Iterates over all truth values by passing them to `blk`
in an unspecified order in an unspecified order
*/ */
fn all_values(blk: block(v: t)) { fn all_values(blk: fn(v: t)) {
blk(tri::false); blk(tri::false);
blk(unknown); blk(unknown);
blk(tri::true); blk(tri::true);

View file

@ -40,7 +40,7 @@ fn sub(t: str, n: int) -> str {
/* Using an interator */ /* Using an interator */
fn ninetynine(it: block(int)) { fn ninetynine(it: fn(int)) {
let n: int = 100; let n: int = 100;
while n > 1 { n -= 1; it(n); } while n > 1 { n -= 1; it(n); }
} }

View file

@ -4,7 +4,7 @@ fn to_lambda1(f: fn@(uint) -> uint) -> fn@(uint) -> uint {
ret f; ret f;
} }
fn to_lambda2(b: block(uint) -> uint) -> fn@(uint) -> uint { fn to_lambda2(b: fn(uint) -> uint) -> fn@(uint) -> uint {
ret to_lambda1({|x| b(x)}); ret to_lambda1({|x| b(x)});
} }

View file

@ -2,11 +2,11 @@
// other tycons. // other tycons.
fn coerce(b: fn()) -> native fn() { fn coerce(b: fn()) -> native fn() {
fn lol(f: native fn(block()) -> native fn(), fn lol(f: native fn(fn()) -> native fn(),
g: fn()) -> native fn() { ret f(g); } g: fn()) -> native fn() { ret f(g); }
fn fn_id(f: native fn()) -> native fn() { ret f } fn fn_id(f: native fn()) -> native fn() { ret f }
ret lol(fn_id, b); ret lol(fn_id, b);
//!^ ERROR mismatched types: expected `native fn(fn&()) -> native fn()` //!^ ERROR mismatched types: expected `native fn(fn()) -> native fn()`
} }
fn main() { fn main() {

View file

@ -1,8 +1,8 @@
// error-pattern: block type can only appear // error-pattern: block type can only appear
fn lol(f: block()) -> block() { ret f; } fn lol(f: fn()) -> fn() { ret f; }
fn main() { fn main() {
let i = 8; let i = 8;
let f = lol(block () { log(error, i); }); let f = lol(fn&() { log(error, i); });
f(); f();
} }

View file

@ -1,5 +1,5 @@
// error-pattern:Tried to deinitialize a variable declared in a different // error-pattern:Tried to deinitialize a variable declared in a different
fn force(f: block()) { f(); } fn force(f: fn()) { f(); }
fn main() { fn main() {
let x = @{x: 17, y: 2}; let x = @{x: 17, y: 2};
let y = @{x: 5, y: 5}; let y = @{x: 5, y: 5};

View file

@ -1,3 +1,3 @@
// error-pattern: not all control paths return // error-pattern: not all control paths return
fn force(f: block() -> int) -> int { f() } fn force(f: fn() -> int) -> int { f() }
fn main() { log(error, force({|| })); } fn main() { log(error, force({|| })); }

View file

@ -1,4 +1,4 @@
// error-pattern: Unsatisfied precondition constraint // error-pattern: Unsatisfied precondition constraint
fn force(f: block()) { f(); } fn force(f: fn()) { f(); }
fn main() { let x: int; force(block () { log(error, x); }); } fn main() { let x: int; force(fn&() { log(error, x); }); }

View file

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value // error-pattern: copying a noncopyable value
fn to_lambda2(b: block(uint) -> uint) -> fn@(uint) -> uint { fn to_lambda2(b: fn(uint) -> uint) -> fn@(uint) -> uint {
// test case where copy clause specifies a value that is not used // test case where copy clause specifies a value that is not used
// in fn@ body, but value is illegal to copy: // in fn@ body, but value is illegal to copy:
ret fn@[copy b](u: uint) -> uint { 22u }; ret fn@[copy b](u: uint) -> uint { 22u };

View file

@ -1,7 +1,7 @@
// error-pattern:assigning to upvar // error-pattern:assigning to upvar
// Make sure that nesting a block within a fn@ doesn't let us // Make sure that nesting a block within a fn@ doesn't let us
// mutate upvars from a fn@. // mutate upvars from a fn@.
fn f2(x: block()) { x(); } fn f2(x: fn()) { x(); }
fn main() { fn main() {
let i = 0; let i = 0;

View file

@ -1,2 +1,2 @@
fn blk1(b: block()) -> fn@() { ret fn@() { }; } fn blk1(b: fn()) -> fn@() { ret fn@() { }; }
fn test1() { (blk1 {|| #debug["hi"]; })(); } fn test1() { (blk1 {|| #debug["hi"]; })(); }

View file

@ -1,6 +1,6 @@
// error-pattern:fail // error-pattern:fail
fn x(it: block(int)) { fn x(it: fn(int)) {
fail; fail;
it(0); it(0);
} }

View file

@ -1,6 +1,6 @@
// error-pattern:fail // error-pattern:fail
fn x(it: block(int)) { fn x(it: fn(int)) {
let a = @0; let a = @0;
it(1); it(1);
} }

View file

@ -4,7 +4,7 @@ fn main() {
let cheese = "roquefort"; let cheese = "roquefort";
let carrots = @"crunchy"; let carrots = @"crunchy";
fn@(tasties: @str, macerate: block(str)) { fn@(tasties: @str, macerate: fn(str)) {
macerate(*tasties); macerate(*tasties);
} (carrots, { |food| } (carrots, { |food|
let mush = food + cheese; let mush = food + cheese;

View file

@ -2,7 +2,7 @@
enum thing { a, b, c, } enum thing { a, b, c, }
fn foo(it: block(int)) { it(10); } fn foo(it: fn(int)) { it(10); }
fn main() { fn main() {
let x = true; let x = true;

View file

@ -6,7 +6,7 @@ fn f1(a: {mutable x: int}, &b: int, -c: int) -> int {
ret r; ret r;
} }
fn f2(a: int, f: block(int)) -> int { f(1); ret a; } fn f2(a: int, f: fn(int)) -> int { f(1); ret a; }
fn main() { fn main() {
let a = {mutable x: 1}, b = 2, c = 3; let a = {mutable x: 1}, b = 2, c = 3;

View file

@ -8,7 +8,11 @@ fn asLambda( f : fn@()->uint ) -> uint {
ret f(); ret f();
} }
fn asBlock( f : block()->uint ) -> uint { fn asBlock( f : fn&()->uint ) -> uint {
ret f();
}
fn asAny( f : fn()->uint ) -> uint {
ret f(); ret f();
} }

View file

@ -1,5 +1,5 @@
fn main() { fn main() {
fn f(i: block() -> uint) -> uint { i() } fn f(i: fn() -> uint) -> uint { i() }
let v = [-1f, 0f, 1f, 2f, 3f]; let v = [-1f, 0f, 1f, 2f, 3f];
let z = vec::foldl(f, v) { |x, _y| x } { || 22u }; let z = vec::foldl(f, v) { |x, _y| x } { || 22u };
assert z == 22u; assert z == 22u;

View file

@ -1,4 +1,4 @@
fn main() { fn main() {
fn as_buf<T>(s: str, f: block(str) -> T) -> T { f(s) } fn as_buf<T>(s: str, f: fn(str) -> T) -> T { f(s) }
as_buf("foo", {|foo: str| -> () log(error, foo);}); as_buf("foo", {|foo: str| -> () log(error, foo);});
} }

View file

@ -1,4 +1,4 @@
fn force(f: block() -> int) -> int { ret f(); } fn force(f: fn() -> int) -> int { ret f(); }
fn main() { fn main() {
fn f() -> int { ret 7; } fn f() -> int { ret 7; }
assert (force(f) == 7); assert (force(f) == 7);

View file

@ -1,4 +1,4 @@
fn iter_vec<T>(v: [T], f: block(T)) { for x: T in v { f(x); } } fn iter_vec<T>(v: [T], f: fn(T)) { for x: T in v { f(x); } }
fn main() { fn main() {
let v = [1, 2, 3, 4, 5, 6, 7]; let v = [1, 2, 3, 4, 5, 6, 7];

View file

@ -1,4 +1,4 @@
fn iter_vec<T>(v: [T], f: block(T)) { for x: T in v { f(x); } } fn iter_vec<T>(v: [T], f: fn(T)) { for x: T in v { f(x); } }
fn main() { fn main() {
let v = [1, 2, 3, 4, 5]; let v = [1, 2, 3, 4, 5];

View file

@ -1,6 +1,6 @@
fn bare() {} fn bare() {}
fn likes_block(f: block()) { f() } fn likes_block(f: fn()) { f() }
fn main() { fn main() {
likes_block(bare); likes_block(bare);

View file

@ -2,7 +2,7 @@
// -*- rust -*- // -*- rust -*-
fn two(it: block(int)) { it(0); it(1); } fn two(it: fn(int)) { it(0); it(1); }
fn main() { fn main() {
let a: [mutable int] = [mutable -1, -1, -1, -1]; let a: [mutable int] = [mutable -1, -1, -1, -1];

View file

@ -1,6 +1,6 @@
fn pairs(it: block((int, int))) { fn pairs(it: fn((int, int))) {
let i: int = 0; let i: int = 0;
let j: int = 0; let j: int = 0;
while i < 10 { it((i, j)); i += 1; j += i; } while i < 10 { it((i, j)); i += 1; j += i; }

View file

@ -10,7 +10,7 @@ fn main() {
assert (sum == 45); assert (sum == 45);
} }
fn first_ten(it: block(int)) { fn first_ten(it: fn(int)) {
let i: int = 0; let i: int = 0;
while i < 10 { #debug("first_ten"); it(i); i = i + 1; } while i < 10 { #debug("first_ten"); it(i); i = i + 1; }
} }

View file

@ -12,10 +12,10 @@ impl of to_str for () {
} }
iface map<T> { iface map<T> {
fn map<U>(f: block(T) -> U) -> [U]; fn map<U>(f: fn(T) -> U) -> [U];
} }
impl <T> of map<T> for [T] { impl <T> of map<T> for [T] {
fn map<U>(f: block(T) -> U) -> [U] { fn map<U>(f: fn(T) -> U) -> [U] {
let r = []; let r = [];
for x in self { r += [f(x)]; } for x in self { r += [f(x)]; }
r r

View file

@ -1,6 +1,6 @@
fn range(a: int, b: int, it: block(int)) { fn range(a: int, b: int, it: fn(int)) {
assert (a < b); assert (a < b);
let i: int = a; let i: int = a;
while i < b { it(i); i += 1; } while i < b { it(i); i += 1; }

View file

@ -1,4 +1,4 @@
fn test(f: block(uint) -> uint) -> uint { fn test(f: fn(uint) -> uint) -> uint {
ret f(22u); ret f(22u);
} }

View file

@ -11,7 +11,7 @@ mod b {
impl util for uint { impl util for uint {
fn str() -> str { uint::str(self) } fn str() -> str { uint::str(self) }
fn times(f: block(uint)) { fn times(f: fn(uint)) {
let c = 0u; let c = 0u;
while c < self { f(c); c += 1u; } while c < self { f(c); c += 1u; }
} }
@ -19,8 +19,8 @@ impl util for uint {
impl util<T> for [T] { impl util<T> for [T] {
fn len() -> uint { vec::len(self) } fn len() -> uint { vec::len(self) }
fn iter(f: block(T)) { for x in self { f(x); } } fn iter(f: fn(T)) { for x in self { f(x); } }
fn map<U>(f: block(T) -> U) -> [U] { fn map<U>(f: fn(T) -> U) -> [U] {
let r = []; let r = [];
for elt in self { r += [f(elt)]; } for elt in self { r += [f(elt)]; }
r r

View file

@ -1,6 +1,6 @@
fn range(lo: uint, hi: uint, it: block(uint)) { fn range(lo: uint, hi: uint, it: fn(uint)) {
let lo_ = lo; let lo_ = lo;
while lo_ < hi { it(lo_); lo_ += 1u; } while lo_ < hi { it(lo_); lo_ += 1u; }
} }

View file

@ -7,7 +7,7 @@ import std::list::*;
// Can't easily be written as a "pure fn" because there's // Can't easily be written as a "pure fn" because there's
// no syntax for specifying that f is pure. // no syntax for specifying that f is pure.
fn pure_foldl<T: copy, U: copy>(ls: list<T>, u: U, f: block(T, U) -> U) -> U { fn pure_foldl<T: copy, U: copy>(ls: list<T>, u: U, f: fn(T, U) -> U) -> U {
alt ls { alt ls {
nil { u } nil { u }
cons(hd, tl) { f(hd, pure_foldl(*tl, f(hd, u), f)) } cons(hd, tl) { f(hd, pure_foldl(*tl, f(hd, u), f)) }