提交 5e13d19c 编写于 作者: N Niko Matsakis

s/block()/fn()/g

上级 04351a84
......@@ -349,7 +349,7 @@ fn configure() -> cargo {
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|
for p in copy v.packages {
b(v, p);
......
......@@ -93,7 +93,7 @@ fn have_crate_data(cstore: cstore, cnum: ast::crate_num) -> bool {
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);};
}
......
......@@ -460,7 +460,7 @@ fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) {
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 paths = ebml::get_doc(md, tag_paths);
let index = ebml::get_doc(paths, tag_index);
......
......@@ -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>]],
write_fn: block(io::writer, T)) {
write_fn: fn(io::writer, T)) {
let writer = ebml_w.writer;
ebml::start_tag(ebml_w, tag_index);
let bucket_locs: [uint] = [];
......
......@@ -16,7 +16,7 @@
// data buffer. Whatever format you choose should not contain pipe characters.
// 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};
......@@ -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,
pser: block(@pstate) -> ast::constr_arg_general_<T>)
pser: fn(@pstate) -> ast::constr_arg_general_<T>)
-> @ty::constr_general<T> {
let sp = ast_util::dummy_sp(); // FIXME: use a real span
let args: [@sp_constr_arg<T>] = [];
......
......@@ -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);
}
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);
checker();
let new_invalid = filter_invalid(*sc.invalid, sc.bs);
......
......@@ -140,7 +140,7 @@ fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
}
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) {
let items = cache.get(mdtag);
for item in items {
......
......@@ -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
// closure.
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);
alt ty::ty_fn_proto(cx.tcx, fty) {
proto_uniq { b(check_send); }
......
......@@ -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: []};
cx.blocks = cons(local, @cx.blocks);
visit();
......
......@@ -26,7 +26,7 @@ fn run(tcx: ty::ctxt, crate: @ast::crate, time_pass: bool) {
}
// 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(); }
let start = std::time::precise_time_s();
thunk();
......
......@@ -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
// if you want to get a normalized pattern out of it.
// 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 {
pat_ident(_, option::none) { it(pat); }
pat_ident(_, option::some(sub)) { it(pat); pat_bindings(sub, it); }
......
......@@ -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,
ids: [ast::ident], sp: codemap::span, sc: scopes) {
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]) {
let val = lookup(ns_val(ns_any_value)), typ = lookup(ns_type),
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 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) {
let ch = checker(e, kind);
for elt: T in elts { add_name(ch, sp, id(elt)); }
......
......@@ -3233,8 +3233,8 @@ fn invoke_full(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
fn invoke_(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
to_zero: [{v: ValueRef, t: ty::t}],
to_revoke: [{v: ValueRef, t: ty::t}],
invoker: block(@block_ctxt, ValueRef, [ValueRef],
BasicBlockRef, BasicBlockRef)) -> @block_ctxt {
invoker: fn(@block_ctxt, ValueRef, [ValueRef],
BasicBlockRef, BasicBlockRef)) -> @block_ctxt {
// FIXME: May be worth turning this into a plain call when there are no
// cleanups to run
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 {
alt s.node {
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,
body: ast::blk, llfndecl: ValueRef,
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 up arguments to the function.
......
......@@ -57,7 +57,7 @@
// closure is allocated in the task heap and is reference counted.
// 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
// 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.
//
// ## Opaque Closures ##
......@@ -637,7 +637,7 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
fn make_null_test(
in_bcx: @block_ctxt,
ptr: ValueRef,
blk: block(@block_ctxt) -> @block_ctxt)
blk: fn(@block_ctxt) -> @block_ctxt)
-> @block_ctxt {
let not_null_bcx = new_sub_block_ctxt(in_bcx, "not null");
let next_bcx = new_sub_block_ctxt(in_bcx, "next");
......
......@@ -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,
fill: block(ValueRef, @block_ctxt) -> @block_ctxt)
fill: fn(ValueRef, @block_ctxt) -> @block_ctxt)
-> ValueRef {
let lcx = @{path: pt, module_path: [], ccx: ccx};
let name = link::mangle_internal_name_by_path(ccx, pt);
......
......@@ -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 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,
fill: ValueRef, f: iter_vec_block) -> @block_ctxt {
......
......@@ -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],
q: block([T], node_id) -> bool,
q: fn([T], node_id) -> bool,
s: [T]) -> bool {
/*
FIXME
......
......@@ -1083,7 +1083,7 @@ fn type_is_native(cx: ctxt, ty: t) -> bool {
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 {
let sty = struct(cx, ty);
if test(sty) { ret true; }
......@@ -1420,7 +1420,7 @@ fn hash_fn(id: uint, args: [arg], rty: t) -> uint {
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>,
b: @sp_constr_arg<T>)
-> 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>],
b: [@sp_constr_arg<T>]) -> bool {
let i: uint = 0u;
......@@ -1930,7 +1930,6 @@ fn unify_fn_proto(e_proto: ast::proto, a_proto: ast::proto,
fn sub_proto(p_sub: ast::proto, p_sup: ast::proto) -> bool {
ret alt (p_sub, p_sup) {
(_, ast::proto_any) { true }
(_, ast::proto_block) { true } /* NDM temporary */
(ast::proto_bare, _) { true }
// Equal prototypes are always subprotos:
......@@ -2083,7 +2082,7 @@ fn variance_transform(a: variance, b: variance) -> variance {
}
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;
for exp in expected_tps {
let act = actual_tps[i];
......
......@@ -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`? */
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::<()>();
fn mark_ident(&&i: ident, _fld: ast_fold, b: bindings,
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 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 {
match_expr(e) {
alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } }
......
......@@ -149,7 +149,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
for word in ["mod", "if", "else", "while", "do", "alt", "for", "break",
"cont", "ret", "be", "fail", "type", "resource", "check",
"assert", "claim", "native", "fn", "pure",
"unsafe", "block", "import", "export", "let", "const",
"unsafe", "import", "export", "let", "const",
"log", "copy", "sendfn", "impl", "iface", "enum"] {
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) ->
[@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 */ }
}
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") {
expect_word(p, "fn");
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>,
f: block(parser) -> T,
f: fn(parser) -> T,
p: parser) -> [T] {
let first = true;
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>,
f: block(parser) -> T, p: parser) -> [T] {
f: fn(parser) -> T, p: parser) -> [T] {
let v = parse_seq_to_before_gt(sep, f, 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>,
f: block(parser) -> T,
f: fn(parser) -> T,
p: parser) -> spanned<[T]> {
let lo = p.span.lo;
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,
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);
p.bump();
ret val;
......@@ -604,7 +601,7 @@ fn seq_sep_none() -> seq_sep {
fn parse_seq_to_before_end<T: copy>(ket: token::token,
sep: seq_sep,
f: block(parser) -> T, p: parser) -> [T] {
f: fn(parser) -> T, p: parser) -> [T] {
let first: bool = true;
let v: [T] = [];
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,
sep: seq_sep, f: block(parser) -> T,
sep: seq_sep, f: fn(parser) -> T,
p: parser) -> spanned<[T]> {
let lo = p.span.lo;
expect(p, bra);
......@@ -813,9 +810,6 @@ fn parse_bottom_expr(p: parser) -> pexpr {
_ { /* fallthrough */ }
}
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") {
ret pexpr(parse_block_expr(p, lo, ast::unchecked_blk));
} else if eat_word(p, "unsafe") {
......
......@@ -210,7 +210,7 @@ fn synth_comment(s: ps, text: str) {
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);
let first = true;
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),
get_span: block(IN) -> codemap::span) {
fn commasep_cmnt<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN),
get_span: fn(IN) -> codemap::span) {
box(s, 0u, b);
let len = vec::len::<IN>(elts);
let i = 0u;
......
......@@ -18,7 +18,7 @@
export get_cargo_root;
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> {
if fs::basename(path) == file { option::some(path) }
......
......@@ -63,7 +63,7 @@ fn xfail_target() -> str {
}
}
fn iter_header(testfile: str, it: block(str)) {
fn iter_header(testfile: str, it: fn(str)) {
let rdr = result::get(io::file_reader(testfile));
while !rdr.eof() {
let ln = rdr.read_line();
......
......@@ -215,7 +215,7 @@ fn fold_ty_rep(j_: @mutable uint, i_: uint, newty_: ast::ty_,
*crate2
}
fn under(n: uint, it: block(uint)) {
fn under(n: uint, it: fn(uint)) {
let i: uint = 0u;
while i < n { it(i); i += 1u; }
}
......
......@@ -75,7 +75,7 @@
brief = "Iterates over all truth values by passing them to `blk` \
in an unspecified order"
)]
fn all_values(blk: block(v: t)) {
fn all_values(blk: fn(v: t)) {
blk(true);
blk(false);
}
......
......@@ -29,7 +29,7 @@ enum t<T, U> {
the result is returned.
*/
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 {
alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
}
......
......@@ -84,7 +84,7 @@
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;
while i < hi { it(i); i += 1; }
}
......
......@@ -36,7 +36,7 @@ enum 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 } }
}
......@@ -70,7 +70,7 @@ fn map<T, U: copy>(opt: t<T>, f: block(T) -> U) -> t<U> {
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) } }
}
......@@ -80,7 +80,7 @@ fn maybe<T, U: copy>(def: U, opt: t<T>, f: block(T) -> U) -> U {
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); } }
}
......
......@@ -110,7 +110,7 @@ fn get_err<T, U: copy>(res: t<T, U>) -> U {
> })
*/
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> {
alt res {
ok(t) { op(t) }
......
......@@ -347,7 +347,7 @@ fn char_range_at(s: str, i: uint) -> {ch: char, next: uint} {
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);
while (pos < len) {
let {ch, next} = char_range_at(s, pos);
......@@ -371,7 +371,7 @@ fn iter_chars(s: str, it: block(char)) {
`true` If execution proceeded correctly, `false` if it was interrupted,
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);
}
......@@ -398,7 +398,7 @@ fn loop_chars(s: str, it: block(char) -> bool) -> bool{
represent valid positions inside `s`
*/
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 result = true;
while i < byte_len {
......@@ -1061,7 +1061,7 @@ unsafe fn buf(s: str) -> sbuf {
> 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)
}
......
......@@ -54,7 +54,7 @@
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;
while i < hi { it(i); i += 1u32; }
}
......
......@@ -54,7 +54,7 @@
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;
while i < hi { it(i); i += 1u64; }
}
......
......@@ -54,7 +54,7 @@
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;
while i < hi { it(i); i += 1u8; }
}
......
......@@ -115,7 +115,7 @@
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;
while i < hi { it(i); i += 1u; }
}
......@@ -136,7 +136,7 @@ fn range(lo: uint, hi: uint, it: block(uint)) {
`true` If execution proceeded correctly, `false` if it was interrupted,
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;
while i < hi {
if (!it(i)) { ret false; }
......
......@@ -26,7 +26,7 @@ fn vec_from_buf_shared<T>(t: *sys::type_desc,
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 @@ fn grow_set<T: copy>(&v: [mutable T], index: uint, initval: T, val: T) {
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 = [];
reserve(result, len(v));
for elem: T in v { result += [f(elem)]; }
......@@ -414,7 +414,7 @@ fn map<T, U>(v: [T], f: block(T) -> U) -> [U] {
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 = [];
reserve(result, len(v));
for elem: T in v {
......@@ -429,7 +429,7 @@ fn map_mut<T: copy, U>(v: [const T], f: block(T) -> U) -> [U] {
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);
if v0_len != len(v1) { fail; }
let u: [V] = [];
......@@ -446,7 +446,7 @@ fn map2<T: copy, U: copy, V>(v0: [T], v1: [U], f: block(T, U) -> V) -> [V] {
If function `f` returns `none` then that element is excluded from
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] {
let result = [];
for elem: T in v {
......@@ -467,7 +467,7 @@ fn filter_map<T: copy, U: copy>(v: [const T], f: block(T) -> option::t<U>)
Apply function `f` to each element of `v` and return a vector containing
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 = [];
for elem: T in v {
if f(elem) { result += [elem]; }
......@@ -492,7 +492,7 @@ fn concat<T: copy>(v: [const [const T]]) -> [T] {
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;
iter(v) { |elt|
accum = p(accum, elt);
......@@ -505,7 +505,7 @@ fn foldl<T: copy, U>(z: T, v: [const U], p: block(T, U) -> T) -> T {
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;
riter(v) { |elt|
accum = p(elt, accum);
......@@ -520,7 +520,7 @@ fn foldr<T, U: copy>(v: [const T], z: U, p: block(T, U) -> U) -> U {
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; } }
ret false;
}
......@@ -532,7 +532,7 @@ fn any<T>(v: [T], f: block(T) -> bool) -> bool {
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 v1_len = len(v1);
let i = 0u;
......@@ -550,7 +550,7 @@ fn any2<T, U>(v0: [T], v1: [U], f: block(T, U) -> bool) -> bool {
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; } }
ret true;
}
......@@ -562,7 +562,7 @@ fn all<T>(v: [T], f: block(T) -> bool) -> bool {
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);
if v0_len != len(v1) { ret false; }
let i = 0u;
......@@ -600,7 +600,7 @@ fn count<T>(x: T, v: [const T]) -> uint {
When function `f` returns true then an option containing the element
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); } }
ret none;
}
......@@ -626,7 +626,7 @@ fn position<T>(x: T, v: [T]) -> option::t<uint> {
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;
while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
ret none;
......@@ -747,7 +747,7 @@ fn enum_uints(start: uint, end: uint) : uint::le(start, end) -> [uint] {
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) }
}
......@@ -757,7 +757,7 @@ fn iter<T>(v: [const T], f: block(T)) {
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;
for elt in v { f(elt, v2[i]); i += 1; }
}
......@@ -770,7 +770,7 @@ fn iter2<U, T>(v: [U], v2: [T], f: block(U, T)) {
Iterates over vector `v` and, for each element, calls function `f` with the
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);
while i < l { f(i, v[i]); i += 1u; }
}
......@@ -784,7 +784,7 @@ fn iteri<T>(v: [const T], f: block(uint, T)) {
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) }
}
......@@ -796,7 +796,7 @@ fn riter<T>(v: [const T], f: block(T)) {
Iterates over vector `v` and, for each element, calls function `f` with the
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);
while 0u < i {
i -= 1u;
......@@ -814,7 +814,7 @@ fn riteri<T>(v: [const T], f: block(uint, T)) {
The total number of permutations produced is `len(v)!`. If `v` contains
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);
if ln == 0u {
put([]);
......
......@@ -53,7 +53,7 @@ fn create(nbits: uint, init: bool) -> t {
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);
assert (vec::len(v0.storage) == len);
assert (v0.nbits == v1.nbits);
......
......@@ -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;
while pos < d.end {
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;
while pos < d.end {
let elt_tag = vint_at(*d.data, pos);
......
......@@ -195,7 +195,7 @@
Iterates over all truth values by passing them to `blk`
in an unspecified order
*/
fn all_values(blk: block(v: t)) {
fn all_values(blk: fn(v: t)) {
blk(both);
blk(four::true);
blk(four::false);
......
......@@ -84,7 +84,7 @@ fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
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 {
empty { }
node(@k, @v, _, _) {
......
......@@ -529,7 +529,7 @@ enum level {
// fsync file after executing blk
// FIXME find better way to create resources within lifetime of outer res
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({
val: *file, opt_level: opt_level,
fsync_fn: fn@(&&file: os::libc::FILE, l: level) -> int {
......@@ -540,7 +540,7 @@ fn FILE_res_sync(&&file: FILE_res, opt_level: option::t<level>,
// fsync fd after executing blk
fn fd_res_sync(&&fd: fd_res, opt_level: option::t<level>,
blk: block(&&res<fd_t>)) {
blk: fn(&&res<fd_t>)) {
blk(res({
val: *fd, opt_level: opt_level,
fsync_fn: fn@(&&fd: fd_t, l: level) -> int {
......@@ -553,7 +553,7 @@ fn fd_res_sync(&&fd: fd_res, opt_level: option::t<level>,
iface t { fn fsync(l: level) -> int; }
// 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({
val: o, opt_level: opt_level,
fsync_fn: fn@(&&o: t, l: level) -> int { ret o.fsync(l); }
......
......@@ -46,7 +46,7 @@ fn from_vec<T: copy>(v: [const T]) -> list<T> {
z - The initial value
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;
iter(ls) {|elt| accum = f(accum, elt);}
accum
......@@ -61,7 +61,7 @@ fn foldl<T: copy, U>(ls: list<U>, z: T, f: block(T, U) -> T) -> T {
When function `f` returns true then an option containing the element
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> {
let ls = ls;
while true {
......@@ -164,7 +164,7 @@ fn len<T>(ls: list<T>) -> uint {
Iterate over a list
*/
fn iter<T>(l: list<T>, f: block(T)) {
fn iter<T>(l: list<T>, f: fn(T)) {
alt l {
cons(hd, tl) {
f(hd);
......
......@@ -88,17 +88,17 @@
Iterate over all the key/value pairs in the map
*/
fn items(block(K, V));
fn items(fn(K, V));
/*
Method: keys
Iterate over all the keys in the map
*/
fn keys(block(K));
fn keys(fn(K));
/*
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
......@@ -246,7 +246,7 @@ fn chains<K: copy, V: copy>(nchains: uint) -> [mutable 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;
while true {
alt chain {
......@@ -261,7 +261,7 @@ fn foreach_entry<K: copy, V: copy>(chain0: 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);
while i < n {
foreach_entry(chains[i], blk);
......@@ -281,7 +281,7 @@ fn rehash<K: copy, V: copy>(tbl: t<K,V>) {
}
}
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.
foreach_chain(tbl_chains) { |entry|
let key = entry.key;
......@@ -310,11 +310,11 @@ fn find(k: K) -> option::t<V> { get(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> {
......
......@@ -81,7 +81,7 @@ fn rot(r: int, x: u32) -> u32 {
fn md4_str(msg: [u8]) -> str {
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);
}
let result = "";
......
......@@ -419,7 +419,7 @@ fn gt(left: rope, right: rope) -> bool {
`true` If execution proceeded correctly, `false` if it was interrupted,
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) {
node::empty { ret true }
node::content(x) { ret node::loop_chars(x, it) }
......@@ -435,7 +435,7 @@ fn loop_chars(rope: rope, it: block(char) -> bool) -> bool {
rope - A rope to traverse. It may be empty
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|
it(x);
ret true
......@@ -466,7 +466,7 @@ fn iter_chars(rope: rope, it: block(char)) {
`true` If execution proceeded correctly, `false` if it was interrupted,
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) {
node::empty { ret true }
node::content(x) {ret node::loop_leaves(x, it)}
......@@ -1135,7 +1135,7 @@ fn cmp(a: @node, b: @node) -> int {
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 str::loop_chars_sub(*leaf.content,
leaf.byte_offset,
......@@ -1159,7 +1159,7 @@ fn loop_chars(node: @node, it: block(char) -> bool) -> bool {
`true` If execution proceeded correctly, `false` if it was interrupted,
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;
while true {
alt(*current) {
......
......@@ -110,7 +110,7 @@ fn contains_key(&&key: uint) -> bool {
fn get(&&key: uint) -> V { get(self, key) }
fn find(&&key: uint) -> option::t<V> { find(self, key) }
fn rehash() { fail }
fn items(it: block(&&uint, V)) {
fn items(it: fn(&&uint, V)) {
let idx = 0u;
for item in self.v {
alt item {
......@@ -122,14 +122,14 @@ fn items(it: block(&&uint, V)) {
idx += 1u;
}
}
fn keys(it: block(&&uint)) {
fn keys(it: fn(&&uint)) {
let idx = 0u;
for item in self.v {
if item != none { it(idx); }
idx += 1u;
}
}
fn values(it: block(V)) {
fn values(it: fn(V)) {
for item in self.v {
alt item { some(elt) { it(elt); } _ {} }
}
......
......@@ -10,7 +10,7 @@
export quick_sort3;
/* Type: lteq */
type lteq<T> = block(T, T) -> bool;
type lteq<T> = fn(T, T) -> bool;
/*
Function: merge_sort
......
......@@ -83,7 +83,7 @@ fn find<K: copy, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
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 {
empty { }
node(k, v, _, _) {
......
......@@ -164,7 +164,7 @@
Iterates over all truth values by passing them to `blk`
in an unspecified order
*/
fn all_values(blk: block(v: t)) {
fn all_values(blk: fn(v: t)) {
blk(tri::false);
blk(unknown);
blk(tri::true);
......
......@@ -40,7 +40,7 @@ fn sub(t: str, n: int) -> str {
/* Using an interator */
fn ninetynine(it: block(int)) {
fn ninetynine(it: fn(int)) {
let n: int = 100;
while n > 1 { n -= 1; it(n); }
}
......
......@@ -4,7 +4,7 @@ fn to_lambda1(f: fn@(uint) -> uint) -> fn@(uint) -> uint {
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)});
}
......
......@@ -2,11 +2,11 @@
// other tycons.
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); }
fn fn_id(f: native fn()) -> native fn() { ret f }
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() {
......
// error-pattern: block type can only appear
fn lol(f: block()) -> block() { ret f; }
fn lol(f: fn()) -> fn() { ret f; }
fn main() {
let i = 8;
let f = lol(block () { log(error, i); });
let f = lol(fn&() { log(error, i); });
f();
}
// error-pattern:Tried to deinitialize a variable declared in a different
fn force(f: block()) { f(); }
fn force(f: fn()) { f(); }
fn main() {
let x = @{x: 17, y: 2};
let y = @{x: 5, y: 5};
......
// 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({|| })); }
// error-pattern: Unsatisfied precondition constraint
fn force(f: block()) { f(); }
fn main() { let x: int; force(block () { log(error, x); }); }
fn force(f: fn()) { f(); }
fn main() { let x: int; force(fn&() { log(error, x); }); }
// 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
// in fn@ body, but value is illegal to copy:
ret fn@[copy b](u: uint) -> uint { 22u };
......
// error-pattern:assigning to upvar
// Make sure that nesting a block within a fn@ doesn't let us
// mutate upvars from a fn@.
fn f2(x: block()) { x(); }
fn f2(x: fn()) { x(); }
fn main() {
let i = 0;
......
fn blk1(b: block()) -> fn@() { ret fn@() { }; }
fn blk1(b: fn()) -> fn@() { ret fn@() { }; }
fn test1() { (blk1 {|| #debug["hi"]; })(); }
// error-pattern:fail
fn x(it: block(int)) {
fn x(it: fn(int)) {
fail;
it(0);
}
......
// error-pattern:fail
fn x(it: block(int)) {
fn x(it: fn(int)) {
let a = @0;
it(1);
}
......
......@@ -4,7 +4,7 @@ fn main() {
let cheese = "roquefort";
let carrots = @"crunchy";
fn@(tasties: @str, macerate: block(str)) {
fn@(tasties: @str, macerate: fn(str)) {
macerate(*tasties);
} (carrots, { |food|
let mush = food + cheese;
......
......@@ -2,7 +2,7 @@
enum thing { a, b, c, }
fn foo(it: block(int)) { it(10); }
fn foo(it: fn(int)) { it(10); }
fn main() {
let x = true;
......
......@@ -6,7 +6,7 @@ fn f1(a: {mutable x: int}, &b: int, -c: int) -> int {
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() {
let a = {mutable x: 1}, b = 2, c = 3;
......
......@@ -8,7 +8,11 @@ fn asLambda( f : fn@()->uint ) -> uint {
ret f();
}
fn asBlock( f : block()->uint ) -> uint {
fn asBlock( f : fn&()->uint ) -> uint {
ret f();
}
fn asAny( f : fn()->uint ) -> uint {
ret f();
}
......
fn main() {
fn f(i: block() -> uint) -> uint { i() }
fn f(i: fn() -> uint) -> uint { i() }
let v = [-1f, 0f, 1f, 2f, 3f];
let z = vec::foldl(f, v) { |x, _y| x } { || 22u };
assert z == 22u;
......
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);});
}
fn force(f: block() -> int) -> int { ret f(); }
fn force(f: fn() -> int) -> int { ret f(); }
fn main() {
fn f() -> int { ret 7; }
assert (force(f) == 7);
......
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() {
let v = [1, 2, 3, 4, 5, 6, 7];
......
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() {
let v = [1, 2, 3, 4, 5];
......
fn bare() {}
fn likes_block(f: block()) { f() }
fn likes_block(f: fn()) { f() }
fn main() {
likes_block(bare);
......
......@@ -2,7 +2,7 @@
// -*- rust -*-
fn two(it: block(int)) { it(0); it(1); }
fn two(it: fn(int)) { it(0); it(1); }
fn main() {
let a: [mutable int] = [mutable -1, -1, -1, -1];
......
fn pairs(it: block((int, int))) {
fn pairs(it: fn((int, int))) {
let i: int = 0;
let j: int = 0;
while i < 10 { it((i, j)); i += 1; j += i; }
......
......@@ -10,7 +10,7 @@ fn main() {
assert (sum == 45);
}
fn first_ten(it: block(int)) {
fn first_ten(it: fn(int)) {
let i: int = 0;
while i < 10 { #debug("first_ten"); it(i); i = i + 1; }
}
......@@ -12,10 +12,10 @@ fn to_str() -> str { "()" }
}
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] {
fn map<U>(f: block(T) -> U) -> [U] {
fn map<U>(f: fn(T) -> U) -> [U] {
let r = [];
for x in self { r += [f(x)]; }
r
......
fn range(a: int, b: int, it: block(int)) {
fn range(a: int, b: int, it: fn(int)) {
assert (a < b);
let i: int = a;
while i < b { it(i); i += 1; }
......
fn test(f: block(uint) -> uint) -> uint {
fn test(f: fn(uint) -> uint) -> uint {
ret f(22u);
}
......
......@@ -11,7 +11,7 @@ impl baz for str { fn plus() -> int { 200 } }
impl util for uint {
fn str() -> str { uint::str(self) }
fn times(f: block(uint)) {
fn times(f: fn(uint)) {
let c = 0u;
while c < self { f(c); c += 1u; }
}
......@@ -19,8 +19,8 @@ fn times(f: block(uint)) {
impl util<T> for [T] {
fn len() -> uint { vec::len(self) }
fn iter(f: block(T)) { for x in self { f(x); } }
fn map<U>(f: block(T) -> U) -> [U] {
fn iter(f: fn(T)) { for x in self { f(x); } }
fn map<U>(f: fn(T) -> U) -> [U] {
let r = [];
for elt in self { r += [f(elt)]; }
r
......
fn range(lo: uint, hi: uint, it: block(uint)) {
fn range(lo: uint, hi: uint, it: fn(uint)) {
let lo_ = lo;
while lo_ < hi { it(lo_); lo_ += 1u; }
}
......
......@@ -7,7 +7,7 @@
// Can't easily be written as a "pure fn" because there's
// 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 {
nil { u }
cons(hd, tl) { f(hd, pure_foldl(*tl, f(hd, u), f)) }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册