Skip to content

Commit 4dcf84e

Browse files
committed
Remove bind. Issue rust-lang#2189
1 parent bcd3942 commit 4dcf84e

File tree

116 files changed

+384
-806
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+384
-806
lines changed

doc/rust.md

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ fn pure_foldl<T, U: copy>(ls: list<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
980980
pure fn pure_length<T>(ls: list<T>) -> uint {
981981
fn count<T>(_t: T, &&u: uint) -> uint { u + 1u }
982982
unchecked {
983-
pure_foldl(ls, 0u, count(_, _))
983+
pure_foldl(ls, 0u, count)
984984
}
985985
}
986986
~~~~
@@ -1941,49 +1941,6 @@ An example of a call expression:
19411941
let x: int = add(1, 2);
19421942
~~~~
19431943

1944-
1945-
### Bind expressions
1946-
1947-
A _bind expression_ constructs a new function from an existing function.^[The
1948-
`bind` expression is analogous to the `bind` expression in the Sather
1949-
language.] The new function has zero or more of its arguments *bound* into a
1950-
new, hidden boxed tuple that holds the bindings. For each concrete argument
1951-
passed in the `bind` expression, the corresponding parameter in the existing
1952-
function is *omitted* as a parameter of the new function. For each argument
1953-
passed the placeholder symbol `_` in the `bind` expression, the corresponding
1954-
parameter of the existing function is *retained* as a parameter of the new
1955-
function.
1956-
1957-
Any subsequent invocation of the new function with residual arguments causes
1958-
invocation of the existing function with the combination of bound arguments
1959-
and residual arguments that was specified during the binding.
1960-
1961-
An example of a `bind` expression:
1962-
1963-
~~~~{.xfail-test}
1964-
fn add(x: int, y: int) -> int {
1965-
ret x + y;
1966-
}
1967-
type single_param_fn = fn(int) -> int;
1968-
1969-
let add4: single_param_fn = bind add(4, _);
1970-
1971-
let add5: single_param_fn = bind add(_, 5);
1972-
1973-
assert (add(4,5) == add4(5));
1974-
assert (add(4,5) == add5(4));
1975-
1976-
~~~~
1977-
1978-
A `bind` expression generally stores a copy of the bound arguments in a
1979-
hidden, boxed tuple, owned by the resulting first-class function. For each
1980-
bound slot in the bound function's signature, space is allocated in the hidden
1981-
tuple and populated with a copy of the bound value.
1982-
1983-
A `bind` expression is an alternative way of constructing a shared function
1984-
closure; the [`fn@` expression](#shared-function-expressions) form is another
1985-
way.
1986-
19871944
### Shared function expressions
19881945

19891946
*TODO*.

doc/tutorial.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -903,19 +903,6 @@ argument to every element of a vector, producing a new vector.
903903
Even when a closure takes no parameters, you must still write the bars
904904
for the parameter list, as in `{|| ...}`.
905905

906-
## Binding
907-
908-
Partial application is done using the `bind` keyword in Rust.
909-
910-
~~~~
911-
let findx = bind str::find_char(_, 'x');
912-
~~~~
913-
914-
Binding a function produces a boxed closure (`fn@` type) in which some
915-
of the arguments to the bound function have already been provided.
916-
`findx` will be a function taking a single string argument, and
917-
returning the position where the letter `x` occurs.
918-
919906
## Iteration
920907

921908
Functions taking closures provide a good way to define non-trivial

src/cargo/cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ fn load_crate(filename: str) -> option<crate> {
328328
mut deps: []
329329
};
330330
let v = visit::mk_simple_visitor(@{
331-
visit_view_item: bind goto_view_item(e, _),
332-
visit_item: bind goto_item(e, _),
331+
visit_view_item: {|a|goto_view_item(e, a)},
332+
visit_item: {|a|goto_item(e, a)},
333333
with *visit::default_simple_visitor()
334334
});
335335

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn compose_and_run_compiler(
325325
let abs_ab = path::connect(config.aux_base, rel_ab);
326326
let aux_args =
327327
make_compile_args(config, props, ["--lib"] + extra_link_args,
328-
bind make_lib_name(_, _, testfile), abs_ab);
328+
{|a,b|make_lib_name(a, b, testfile)}, abs_ab);
329329
let auxres = compose_and_run(config, abs_ab, aux_args, [],
330330
config.compile_lib_path, option::none);
331331
if auxres.status != 0 {

src/fuzzer/fuzzer.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ fn steal(crate: ast::crate, tm: test_mode) -> stolen_stuff {
139139
let exprs = @mut [];
140140
let tys = @mut [];
141141
let v = visit::mk_simple_visitor(@{
142-
visit_expr: bind stash_expr_if(safe_to_steal_expr, exprs, _, tm),
143-
visit_ty: bind stash_ty_if(safe_to_steal_ty, tys, _, tm)
142+
visit_expr: {|a|stash_expr_if(safe_to_steal_expr, exprs, a, tm)},
143+
visit_ty: {|a|stash_ty_if(safe_to_steal_ty, tys, a, tm)}
144144
with *visit::default_simple_visitor()
145145
});
146146
visit::visit_crate(crate, (), v);
@@ -188,8 +188,8 @@ fn replace_expr_in_crate(crate: ast::crate, i: uint,
188188
}
189189
}
190190
let afp =
191-
@{fold_expr: fold::wrap(bind fold_expr_rep(j, i,
192-
newexpr.node, _, _, tm))
191+
@{fold_expr: fold::wrap({|a,b|
192+
fold_expr_rep(j, i, newexpr.node, a, b, tm)})
193193
with *fold::default_ast_fold()};
194194
let af = fold::make_fold(afp);
195195
let crate2: @ast::crate = @af.fold_crate(crate);
@@ -211,7 +211,7 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty,
211211
} else { fold::noop_fold_ty(original, fld) }
212212
}
213213
let afp =
214-
@{fold_ty: fold::wrap(bind fold_ty_rep(j, i, newty.node, _, _, tm))
214+
@{fold_ty: fold::wrap({|a,b|fold_ty_rep(j, i, newty.node, a, b, tm)})
215215
with *fold::default_ast_fold()};
216216
let af = fold::make_fold(afp);
217217
let crate2: @ast::crate = @af.fold_crate(crate);
@@ -235,7 +235,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
235235
filename: str, cx: context) {
236236
let stolen = steal(crate, cx.mode);
237237
let extra_exprs = vec::filter(common_exprs(),
238-
bind safe_to_use_expr(_, cx.mode));
238+
{|a|safe_to_use_expr(a, cx.mode)});
239239
check_variants_T(crate, codemap, filename, "expr",
240240
extra_exprs + stolen.exprs, pprust::expr_to_str,
241241
replace_expr_in_crate, cx);
@@ -268,13 +268,13 @@ fn check_variants_T<T: copy>(
268268
// testing the string for stability is easier and ok for now.
269269
let handler = diagnostic::mk_handler(none);
270270
let str3 =
271-
@as_str(bind pprust::print_crate(
271+
@as_str({|a|pprust::print_crate(
272272
codemap,
273273
diagnostic::mk_span_handler(handler, codemap),
274274
crate2,
275275
filename,
276-
io::str_reader(""), _,
277-
pprust::no_ann()));
276+
io::str_reader(""), a,
277+
pprust::no_ann())});
278278
alt cx.mode {
279279
tm_converge {
280280
check_roundtrip_convergence(str3, 1u);
@@ -421,12 +421,12 @@ fn parse_and_print(code: @str) -> str {
421421
let crate = parse::parse_crate_from_source_str(
422422
filename, code, [], sess);
423423
io::with_str_reader(*code) { |rdr|
424-
as_str(bind pprust::print_crate(sess.cm,
424+
as_str({|a|pprust::print_crate(sess.cm,
425425
sess.span_diagnostic,
426426
crate,
427427
filename,
428-
rdr, _,
429-
pprust::no_ann()))
428+
rdr, a,
429+
pprust::no_ann())})
430430
}
431431
}
432432

@@ -439,7 +439,7 @@ fn has_raw_pointers(c: ast::crate) -> bool {
439439
}
440440
}
441441
let v =
442-
visit::mk_simple_visitor(@{visit_ty: bind visit_ty(has_rp, _)
442+
visit::mk_simple_visitor(@{visit_ty: {|a|visit_ty(has_rp, a)}
443443
with *visit::default_simple_visitor()});
444444
visit::visit_crate(c, (), v);
445445
ret *has_rp;
@@ -565,12 +565,12 @@ fn check_variants(files: [str], cx: context) {
565565
s, [], sess);
566566
io::with_str_reader(*s) { |rdr|
567567
#error("%s",
568-
as_str(bind pprust::print_crate(sess.cm,
568+
as_str({|a|pprust::print_crate(sess.cm,
569569
sess.span_diagnostic,
570570
crate,
571571
file,
572-
rdr, _,
573-
pprust::no_ann())));
572+
rdr, a,
573+
pprust::no_ann())}));
574574
}
575575
check_variants_of_ast(*crate, sess.cm, file, cx);
576576
}

src/libcore/comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ fn peek<T: send>(p: port<T>) -> bool { peek_(***p) }
177177

178178
#[doc(hidden)]
179179
fn recv_chan<T: send>(ch: comm::chan<T>) -> T {
180-
as_raw_port(ch, recv_(_))
180+
as_raw_port(ch, {|x|recv_(x)})
181181
}
182182

183183
fn peek_chan<T: send>(ch: comm::chan<T>) -> bool {
184-
as_raw_port(ch, peek_(_))
184+
as_raw_port(ch, {|x|peek_(x)})
185185
}
186186

187187
#[doc = "Receive on a raw port pointer"]

src/libcore/extfmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ mod ct {
174174
let curr: [flag] = [f];
175175
ret {flags: curr + rest, next: j};
176176
}
177-
let more = bind more_(_, s, i, lim);
177+
let more = {|x|more_(x, s, i, lim)};
178178
let f = s[i];
179179
ret if f == '-' as u8 {
180180
more(flag_left_justify)

src/libstd/bitv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Converts the bitvector to a vector of uint with the same length.
185185
Each uint in the resulting vector has either value 0u or 1u.
186186
"]
187187
fn to_vec(v: bitv) -> [uint] {
188-
let sub = bind init_to_vec(v, _);
188+
let sub = {|x|init_to_vec(v, x)};
189189
ret vec::from_fn::<uint>(v.nbits, sub);
190190
}
191191

src/libstd/c_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod tests {
136136
assert mem as int != 0;
137137

138138
ret unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
139-
bind free(mem)) };
139+
{||free(mem)}) };
140140
}
141141

142142
#[test]

src/libstd/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ mod tests {
292292
two(17, 42));
293293

294294
#debug("*** test parameterized: taggypar<int>");
295-
let eq4: eqfn<taggypar<int>> = bind taggypareq::<int>(_, _);
295+
let eq4: eqfn<taggypar<int>> = {|x,y|taggypareq::<int>(x, y)};
296296
test_parameterized::<taggypar<int>>(eq4, onepar::<int>(1),
297297
twopar::<int>(1, 2),
298298
threepar::<int>(1, 2, 3),

src/libstd/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn run_tests_console(opts: test_opts,
162162
mut ignored: 0u,
163163
mut failures: []};
164164

165-
run_tests(opts, tests, bind callback(_, st));
165+
run_tests(opts, tests, {|x|callback(x, st)});
166166

167167
assert (st.passed + st.failed + st.ignored == st.total);
168168
let success = st.failed == 0u;
@@ -349,7 +349,7 @@ fn filter_tests(opts: test_opts,
349349
} else { ret option::none; }
350350
}
351351

352-
let filter = bind filter_fn(_, filter_str);
352+
let filter = {|x|filter_fn(x, filter_str)};
353353

354354
vec::filter_map(filtered, filter)
355355
};
@@ -367,7 +367,7 @@ fn filter_tests(opts: test_opts,
367367
} else { ret option::none; }
368368
};
369369

370-
vec::filter_map(filtered, bind filter(_))
370+
vec::filter_map(filtered, {|x|filter(x)})
371371
};
372372

373373
// Sort the tests alphabetically
@@ -376,7 +376,7 @@ fn filter_tests(opts: test_opts,
376376
fn lteq(t1: test_desc, t2: test_desc) -> bool {
377377
str::le(t1.name, t2.name)
378378
}
379-
sort::merge_sort(bind lteq(_, _), filtered)
379+
sort::merge_sort({|x,y|lteq(x, y)}, filtered)
380380
};
381381

382382
ret filtered;

src/libstd/treemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mod tests {
125125
fn t(n: @mut int, &&k: int, &&_v: ()) {
126126
assert (*n == k); *n += 1;
127127
}
128-
traverse(m, bind t(n, _, _));
128+
traverse(m, {|x,y|t(n, x, y)});
129129
}
130130

131131
#[test]

src/libsyntax/ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ enum expr_ {
300300
expr_rec([field], option<@expr>),
301301
expr_call(@expr, [@expr], bool), // True iff last argument is a block
302302
expr_tup([@expr]),
303-
expr_bind(@expr, [option<@expr>]),
304303
expr_binary(binop, @expr, @expr),
305304
expr_unary(unop, @expr),
306305
expr_lit(@lit),

src/libsyntax/ext/auto_serialize.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl helpers for ext_ctxt {
267267
}
268268

269269
let fld = fold::make_fold(@{
270-
new_span: repl_sp(_, ast_util::dummy_sp(), span)
270+
new_span: {|a|repl_sp(a, ast_util::dummy_sp(), span)}
271271
with *fold::default_ast_fold()
272272
});
273273

@@ -757,8 +757,8 @@ fn ty_fns(cx: ext_ctxt, name: ast::ident, ty: @ast::ty, tps: [ast::ty_param])
757757

758758
let span = ty.span;
759759
[
760-
mk_ser_fn(cx, span, name, tps, ser_ty(_, _, ty, _, _)),
761-
mk_deser_fn(cx, span, name, tps, deser_ty(_, _, ty, _))
760+
mk_ser_fn(cx, span, name, tps, {|a,b,c,d|ser_ty(a, b, ty, c, d)}),
761+
mk_deser_fn(cx, span, name, tps, {|a,b,c|deser_ty(a, b, ty, c)})
762762
]
763763
}
764764

@@ -860,8 +860,8 @@ fn enum_fns(cx: ext_ctxt, e_name: ast::ident, e_span: span,
860860
-> [@ast::item] {
861861
[
862862
mk_ser_fn(cx, e_span, e_name, tps,
863-
ser_enum(_, _, e_name, e_span, variants, _, _)),
863+
{|a,b,c,d|ser_enum(a, b, e_name, e_span, variants, c, d)}),
864864
mk_deser_fn(cx, e_span, e_name, tps,
865-
deser_enum(_, _, e_name, e_span, variants, _))
865+
{|a,b,c|deser_enum(a, b, e_name, e_span, variants, c)})
866866
]
867867
}

src/libsyntax/ext/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ fn expand_crate(parse_sess: parse::parse_sess,
130130
let afp = default_ast_fold();
131131
let cx: ext_ctxt = mk_ctxt(parse_sess, cfg);
132132
let f_pre =
133-
@{fold_expr: bind expand_expr(exts, cx, _, _, _, afp.fold_expr),
134-
fold_mod: bind expand_mod_items(exts, cx, _, _, afp.fold_mod),
135-
fold_item: bind expand_item(cx, _, _, afp.fold_item),
136-
new_span: bind new_span(cx, _)
133+
@{fold_expr: {|a,b,c|expand_expr(exts, cx, a, b, c, afp.fold_expr)},
134+
fold_mod: {|a,b|expand_mod_items(exts, cx, a, b, afp.fold_mod)},
135+
fold_item: {|a,b|expand_item(cx, a, b, afp.fold_item)},
136+
new_span: {|a|new_span(cx, a)}
137137
with *afp};
138138
let f = make_fold(f_pre);
139139
let cm = parse_expr_from_source_str("<core-macros>",

src/libsyntax/ext/fmt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
2323
fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: str) -> ! {
2424
cx.span_fatal(sp, msg);
2525
}
26-
let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _);
26+
let parse_fmt_err = fn@(s: str) -> ! {
27+
parse_fmt_err_(cx, fmtspan, s)
28+
};
2729
let pieces = parse_fmt_string(fmt, parse_fmt_err);
2830
ret pieces_to_expr(cx, sp, pieces, args);
2931
}

src/libsyntax/ext/qquote.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ fn replace<T>(node: T, repls: [fragment], ff: fn (ast_fold, T) -> T)
274274
-> T
275275
{
276276
let aft = default_ast_fold();
277-
let f_pre = @{fold_expr: bind replace_expr(repls, _, _, _,
278-
aft.fold_expr),
279-
fold_ty: bind replace_ty(repls, _, _, _,
280-
aft.fold_ty)
277+
let f_pre = @{fold_expr: {|a,b,c|replace_expr(repls, a, b, c,
278+
aft.fold_expr)},
279+
fold_ty: {|a,b,c|replace_ty(repls, a, b, c,
280+
aft.fold_ty)}
281281
with *aft};
282282
ret ff(make_fold(f_pre), node);
283283
}

0 commit comments

Comments
 (0)