fn main(args: [str]) {
let n = 7;
log #fmt("Pfannkuchen(%d) = %d", n, fannkuch(n));
-}
\ No newline at end of file
+}
}
// Body::props is a record of floats, so
-// vec[Body::props] is a vector of records of floats
+// vec<Body::props> is a vector of records of floats
mod NBodySystem {
import std::comm::send;
fn fib(n: int) -> int {
- fn pfib(c: _chan[int], n: int) {
+ fn pfib(c: _chan<int>, n: int) {
if n == 0 {
send(c, 0);
} else if (n <= 2) {
send(c, 1);
} else {
- let p = mk_port[int]();
+ let p = mk_port<int>();
let t1 = task::_spawn(bind pfib(p.mk_chan(), n - 1));
let t2 = task::_spawn(bind pfib(p.mk_chan(), n - 2));
type mapper = fn(str, putter) ;
- type getter = fn() -> option[int] ;
+ type getter = fn() -> option<int> ;
type reducer = fn(str, getter) ;
tag ctrl_proto {
- find_reducer([u8], _chan[_chan[reduce_proto]]);
+ find_reducer([u8], _chan<_chan<reduce_proto>>);
mapper_done;
}
tag reduce_proto { emit_val(int); done; ref; release; }
- fn start_mappers(ctrl: _chan[ctrl_proto], inputs: &[str]) -> [task_id] {
+ fn start_mappers(ctrl: _chan<ctrl_proto>, inputs: &[str]) -> [task_id] {
let tasks = ~[];
for i: str in inputs {
tasks += ~[task::_spawn(bind map_task(ctrl, i))];
ret tasks;
}
- fn map_task(ctrl: _chan[ctrl_proto], input: str) {
+ fn map_task(ctrl: _chan<ctrl_proto>, input: str) {
// log_err "map_task " + input;
let intermediates = map::new_str_hash();
- fn emit(im: &map::hashmap[str, _chan[reduce_proto]],
- ctrl: _chan[ctrl_proto], key: str, val: int) {
+ fn emit(im: &map::hashmap<str, _chan<reduce_proto>>,
+ ctrl: _chan<ctrl_proto>, key: str, val: int) {
let c;
alt im.find(key) {
some(_c) {
c = _c
}
none. {
- let p = mk_port[_chan[reduce_proto]]();
+ let p = mk_port<_chan<reduce_proto>>();
let keyi = str::bytes(key);
send(ctrl, find_reducer(keyi, p.mk_chan()));
c = p.recv();
map(input, bind emit(intermediates, ctrl, _, _));
- for each kv: @{key: str, val: _chan[reduce_proto]} in
+ for each kv: @{key: str, val: _chan<reduce_proto>} in
intermediates.items() {
send(kv.val, release);
}
send(ctrl, mapper_done);
}
- fn reduce_task(key: str, out: _chan[_chan[reduce_proto]]) {
+ fn reduce_task(key: str, out: _chan<_chan<reduce_proto>>) {
let p = mk_port();
send(out, p.mk_chan());
let ref_count = 0;
let is_done = false;
- fn get(p: &_port[reduce_proto], ref_count: &mutable int,
- is_done: &mutable bool) -> option[int] {
+ fn get(p: &_port<reduce_proto>, ref_count: &mutable int,
+ is_done: &mutable bool) -> option<int> {
while !is_done || ref_count > 0 {
alt p.recv() {
emit_val(v) {
}
fn map_reduce(inputs: &[str]) {
- let ctrl = mk_port[ctrl_proto]();
+ let ctrl = mk_port<ctrl_proto>();
// This task becomes the master control task. It task::_spawns
// to do the rest.
- let reducers: map::hashmap[str, _chan[reduce_proto]];
+ let reducers: map::hashmap<str, _chan<reduce_proto>>;
reducers = map::new_str_hash();
}
}
- for each kv: @{key: str, val: _chan[reduce_proto]} in reducers.items()
+ for each kv: @{key: str, val: _chan<reduce_proto>} in reducers.items()
{
send(kv.val, done);
}
log_err "MapReduce completed in " + u64::str(elapsed) + "ms";
}
-fn read_word(r: io::reader) -> option[str] {
+fn read_word(r: io::reader) -> option<str> {
let w = "";
while !r.eof() {
mod m1 { }
-fn main(args: [str]) { log m1::a; }
\ No newline at end of file
+fn main(args: [str]) { log m1::a; }
mod a { }
}
-fn main(args: [str]) { log m1::a; }
\ No newline at end of file
+fn main(args: [str]) { log m1::a; }
import std::map::hashmap;
import std::bitv;
-type fn_info = {vars: hashmap[uint, var_info]};
+type fn_info = {vars: hashmap<uint, var_info>};
type var_info = {a: uint, b: uint};
fn bitv_to_str(enclosing: fn_info, v: bitv::t) -> str {
mod zed {
fn bar() { log "bar"; }
}
-fn main(args: [str]) { bar(); }
\ No newline at end of file
+fn main(args: [str]) { bar(); }
mod zed {
fn bar() { log "bar3"; }
}
-fn main(args: [str]) { bar(); }
\ No newline at end of file
+fn main(args: [str]) { bar(); }
// error-pattern: unresolved modulename
import main::bar;
-fn main(args: [str]) { log "foo"; }
\ No newline at end of file
+fn main(args: [str]) { log "foo"; }
import zed::bar;
import bar::zed;
-fn main(args: [str]) { log "loop"; }
\ No newline at end of file
+fn main(args: [str]) { log "loop"; }
type x = [x];
-fn main() { let b: x = ~[]; }
\ No newline at end of file
+fn main() { let b: x = ~[]; }
// error-pattern:Attempt to use a type argument out of scope
fn hd[U](v: &[U]) -> U {
fn hd1(w: &[U]) -> U { ret w.(0); }
+
ret hd1(v);
-}
\ No newline at end of file
+}
// error-pattern: mismatched types
-tag bar { t1((), option::t[[int]]); t2; }
+tag bar { t1((), option::t<[int]>); t2; }
fn foo(t: bar) -> int { alt t { t1(_, some(x)) { ret x * 3; } _ { fail; } } }
-fn main() { }
\ No newline at end of file
+fn main() { }
// error-pattern: mismatched types
-tag bar { t1((), option::t[[int]]); t2; }
+tag bar { t1((), option::t<[int]>); t2; }
fn foo(t: bar) { alt t { t1(_, some[int](x)) { log x; } _ { fail; } } }
-fn main() { }
\ No newline at end of file
+fn main() { }
log v.some_field_name; //type error
}
-fn main() { }
\ No newline at end of file
+fn main() { }
fn test() { let w: [int]; w.(5) = 0; }
-fn main() { test(); }
\ No newline at end of file
+fn main() { test(); }
// error-pattern:assignment to immutable vec content
-fn main() { let v: [int] = ~[1, 2, 3]; v.(1) = 4; }
\ No newline at end of file
+fn main() { let v: [int] = ~[1, 2, 3]; v.(1) = 4; }
// Run ignored tests
run_ignored: bool,
// Only run tests that match this filter
- filter: option::t[str],
+ filter: option::t<str>,
// A command line to prefix program execution with,
// for running under valgrind
- runtool: option::t[str],
+ runtool: option::t<str>,
// Flags to pass to the compiler
- rustcflags: option::t[str],
+ rustcflags: option::t<str>,
// Explain what's going on
verbose: bool
};
logv(c, #fmt("\n"));
}
-fn opt_str(maybestr: option::t[str]) -> str {
+fn opt_str(maybestr: option::t<str>) -> str {
alt maybestr { option::some(s) { s } option::none. { "(none)" } }
}
-fn str_opt(maybestr: str) -> option::t[str] {
+fn str_opt(maybestr: str) -> option::t<str> {
if maybestr != "(none)" { option::some(maybestr) } else { option::none }
}
fn make_tests(cx: &cx) -> tests_and_conv_fn {
log #fmt("making tests from %s", cx.config.src_base);
- let configport = mk_port[[u8]]();
+ let configport = mk_port<[u8]>();
let tests = ~[];
for file: str in fs::list_dir(cx.config.src_base) {
log #fmt("inspecting file %s", file);
ret valid;
}
-fn make_test(cx: &cx, testfile: &str, configport: &_port[[u8]]) ->
+fn make_test(cx: &cx, testfile: &str, configport: &_port<[u8]>) ->
test::test_desc {
{name: make_test_name(cx.config, testfile),
fn: make_test_closure(testfile, configport.mk_chan()),
Really convoluted. Need to think up of a better definition for tests.
*/
-fn make_test_closure(testfile: &str, configchan: _chan[[u8]]) -> test::test_fn
+fn make_test_closure(testfile: &str, configchan: _chan<[u8]>) -> test::test_fn
{
bind send_config(testfile, configchan)
}
-fn send_config(testfile: str, configchan: _chan[[u8]]) {
+fn send_config(testfile: str, configchan: _chan<[u8]>) {
send(configchan, str::bytes(testfile));
}
function.
*/
-fn closure_to_task(cx: cx, configport: _port[[u8]], testfn: &fn() ) -> task_id
+fn closure_to_task(cx: cx, configport: _port<[u8]>, testfn: &fn() ) -> task_id
{
testfn();
let testfile = configport.recv();
// Lines that should be expected, in order, on standard out
error_patterns: [str],
// Extra flags to pass to the compiler
- compile_flags: option::t[str],
+ compile_flags: option::t<str>,
// If present, the name of a file that this test should match when
// pretty-printed
- pp_exact: option::t[str],
+ pp_exact: option::t<str>,
// FIXME: no-valgrind is a temporary directive until all of run-fail
// is valgrind-clean
no_valgrind: bool
}
}
-fn parse_error_pattern(line: &str) -> option::t[str] {
+fn parse_error_pattern(line: &str) -> option::t<str> {
parse_name_value_directive(line, "error-pattern")
}
-fn parse_compile_flags(line: &str) -> option::t[str] {
+fn parse_compile_flags(line: &str) -> option::t<str> {
parse_name_value_directive(line, "compile-flags")
}
-fn parse_pp_exact(line: &str, testfile: &str) -> option::t[str] {
+fn parse_pp_exact(line: &str, testfile: &str) -> option::t<str> {
alt parse_name_value_directive(line, "pp-exact") {
option::some(s) { option::some(s) }
option::none. {
}
fn parse_name_value_directive(line: &str,
- directive: &str) -> option::t[str] {
+ directive: &str) -> option::t<str> {
let keycolon = directive + ":";
if str::find(line, keycolon) >= 0 {
let colon = str::find(line, keycolon) as uint;
export close;
export reqchan;
-type reqchan = _chan[request];
+type reqchan = _chan<request>;
-type handle = {task: option::t[task_id], chan: reqchan};
+type handle = {task: option::t<task_id>, chan: reqchan};
tag request {
- exec([u8], [u8], [[u8]], _chan[response]);
+ exec([u8], [u8], [[u8]], _chan<response>);
stop;
}
fn mk() -> handle {
let setupport = mk_port();
- let task = task::_spawn(bind fn(setupchan: _chan[_chan[request]]) {
+ let task = task::_spawn(bind fn(setupchan: _chan<_chan<request>>) {
let reqport = mk_port();
let reqchan = reqport.mk_chan();
send(setupchan, reqchan);
}
fn run(handle: &handle, lib_path: &str,
- prog: &str, args: &[str], input: &option::t[str]) ->
+ prog: &str, args: &[str], input: &option::t<str>) ->
{status: int, out: str, err: str} {
- let p = mk_port[response]();
+ let p = mk_port<response>();
let ch = p.mk_chan();
send(handle.chan, exec(str::bytes(lib_path),
str::bytes(prog),
ret {status: status, out: output, err: errput};
}
-fn writeclose(fd: int, s: &option::t[str]) {
+fn writeclose(fd: int, s: &option::t<str>) {
if option::is_some(s) {
let writer = io::new_writer(
io::fd_buf_writer(fd, option::none));
ret buf;
}
-fn worker(p: _port[request]) {
+fn worker(p: _port<request>) {
// FIXME (787): If we declare this inside of the while loop and then
// break out of it before it's ever initialized (i.e. we don't run
fn compose_and_run(cx: &cx, testfile: &str,
make_args: fn(&config, &str) -> procargs ,
lib_path: &str,
- input: option::t[str]) -> procres {
+ input: option::t<str>) -> procres {
let procargs = make_args(cx.config, testfile);
ret program_output(cx, testfile, lib_path,
procargs.prog, procargs.args,
ret {prog: args.(0), args: vec::slice(args, 1u, vec::len(args))};
}
-fn split_maybe_args(argstr: &option::t[str]) -> [str] {
+fn split_maybe_args(argstr: &option::t<str>) -> [str] {
fn rm_whitespace(v: &[str]) -> [str] {
- fn flt(s: &str) -> option::t[str] {
+ fn flt(s: &str) -> option::t<str> {
if !is_whitespace(s) {
option::some(s)
} else {
}
fn program_output(cx: &cx, testfile: &str, lib_path: &str, prog: &str,
- args: &[str], input: option::t[str]) -> procres {
+ args: &[str], input: option::t<str>) -> procres {
let cmdline =
{
let cmdline = make_cmdline(lib_path, prog, args);
// error-pattern:quux
-fn test00_start(ch: chan_t[int], message: int) {
+fn test00_start(ch: chan_t<int>, message: int) {
send(ch, message);
}
port : port_id
};
-fn send[~T](ch : chan_t[T], data : -T) { fail; }
+fn send[~T](ch : chan_t<T>, data : -T) { fail; }
fn main() { fail "quux"; }
import std::comm::mk_port;
import std::comm::send;
-fn echo[~T](c: _chan[T], oc: _chan[_chan[T]]) {
+fn echo[~T](c: _chan<T>, oc: _chan<_chan<T>>) {
// Tests that the type argument in port gets
// visited
let p = mk_port[T]();
// xfail-stage2
// xfail-stage3
io fn main() {
- let port[int] po = port();
+ let port<int> po = port();
// Spawn 10 tasks each sending us back one int.
let int i = 10;
log "main thread exiting";
}
-io fn child(int x, chan[int] ch) {
+io fn child(int x, chan<int> ch) {
log x;
ch <| x;
}
This program should hang on the po |> r line.
*/
fn main() {
- let po: port[int] = port();
- let ch: chan[int] = chan(po);
+ let po: port<int> = port();
+ let ch: chan<int> = chan(po);
let r;
po |> r;
ch <| 42;
log_err r;
-}
\ No newline at end of file
+}
// Bounds-check failure.
assert (v.(x + 2) == 20);
-}
\ No newline at end of file
+}
// Bounds-check failure.
assert (v.(x - 1) == 20);
-}
\ No newline at end of file
+}
import std::comm;
import std::task;
-fn f(c: comm::_chan[int]) {
+fn f(c: comm::_chan<int>) {
type t = {_0: int, _1: int, _2: int};
// Allocate a box.
i = p.recv();
log "parent exiting, killing child";
-}
\ No newline at end of file
+}
tag sty { ty_nil; }
-type raw_t = {struct: sty, cname: option::t[str], hash: uint};
+type raw_t = {struct: sty, cname: option::t<str>, hash: uint};
-fn mk_raw_ty(st: sty, cname: &option::t[str]) -> raw_t {
+fn mk_raw_ty(st: sty, cname: &option::t<str>) -> raw_t {
ret {struct: st, cname: cname, hash: 0u};
}
-fn main() { mk_raw_ty(ty_nil, none[str]); }
\ No newline at end of file
+fn main() { mk_raw_ty(ty_nil, none[str]); }
tag option[T] { some(T); none; }
-type r[T] = {mutable v: [option[T]]};
+type r[T] = {mutable v: [option<T>]};
fn f[T]() -> [T] { ret ~[]; }
-fn main() { let r: r[int] = {mutable v: ~[]}; r.v = f(); }
+fn main() { let r: r<int> = {mutable v: ~[]}; r.v = f(); }
import std::option::none;
import std::option::some;
-fn foo[T](y: &option::t[T]) {
+fn foo[T](y: &option::t<T>) {
let x: int;
let rs: [int] = ~[];
/* tests that x doesn't get put in the precondition for the
ret;
}
-fn main() { log "hello"; foo[int](some[int](5)); }
\ No newline at end of file
+fn main() { log "hello"; foo[int](some[int](5)); }
tag maybe[T] { nothing; just(T); }
-fn foo(x: maybe[int]) {
+fn foo(x: maybe<int>) {
alt x { nothing. { log_err "A"; } just(a) { log_err "B"; } }
}
-fn main() { }
\ No newline at end of file
+fn main() { }
import std::comm::send;
import std::task;
-fn a(c: _chan[int]) { send(c, 10); }
+fn a(c: _chan<int>) { send(c, 10); }
fn main() {
let p = mk_port();
// log "Finished.";
}
-fn b(c: _chan[int]) {
+fn b(c: _chan<int>) {
// log "task b0";
// log "task b1";
// log "task b2";
// log "task b4";
// log "task b5";
send(c, 10);
-}
\ No newline at end of file
+}
import std::comm::_chan;
import std::task;
-fn a(c: _chan[int]) { log "task a0"; log "task a1"; send(c, 10); }
+fn a(c: _chan<int>) { log "task a0"; log "task a1"; send(c, 10); }
fn main() {
let p = comm::mk_port();
log "Finished.";
}
-fn b(c: _chan[int]) {
+fn b(c: _chan<int>) {
log "task b0";
log "task b1";
log "task b2";
log "task b2";
log "task b3";
send(c, 10);
-}
\ No newline at end of file
+}
import std::comm::_chan;
import std::task;
-fn a(c: _chan[int]) {
+fn a(c: _chan<int>) {
if true {
log "task a";
log "task a";
log "children finished, root finishing";
}
-fn b(c: _chan[int]) {
+fn b(c: _chan<int>) {
if true {
log "task b";
log "task b";
log "task b";
}
send(c, 10);
-}
\ No newline at end of file
+}
}
fn test_chan() {
- let p: comm::_port[int] = comm::mk_port();
+ let p: comm::_port<int> = comm::mk_port();
let ch1 = p.mk_chan();
let ch2 = p.mk_chan();
}
native "rust" mod native_mod = "" {
- fn str_byte_len(s: str) -> vec[u8];
+ fn str_byte_len(s: str) -> vec<u8>;
// This isn't actually the signature of str_alloc, but since
// we're not calling it that shouldn't matter
- fn str_alloc(s: str) -> vec[u8];
+ fn str_alloc(s: str) -> vec<u8>;
}
// FIXME: comparison of native fns
if is_odd(n) && length_is_even(some_box(1)) { log_err "bloop"; }
}
-fn main() { foo(67, 5); }
\ No newline at end of file
+fn main() { foo(67, 5); }
if is_odd(n) || length_is_even(some_box(1)) { log_err "bloop"; }
}
-fn main() { foo(67, 5); }
\ No newline at end of file
+fn main() { foo(67, 5); }
type box[T] = {c: @T};
-fn unbox[T](b: &box[T]) -> T { ret *b.c; }
+fn unbox[T](b: &box<T>) -> T { ret *b.c; }
fn main() {
let foo: int = 17;
- let bfoo: box[int] = {c: @foo};
+ let bfoo: box<int> = {c: @foo};
log "see what's in our box";
assert (unbox[int](bfoo) == foo);
-}
\ No newline at end of file
+}
tag request {
quit;
- close(_chan[bool]);
+ close(_chan<bool>);
}
-type ctx = _chan[request];
+type ctx = _chan<request>;
-fn request_task(c: _chan[ctx]) {
+fn request_task(c: _chan<ctx>) {
let p = mk_port();
send(c, p.mk_chan());
let req: request;
fn main() {
let cx = new();
- let p = mk_port[bool]();
+ let p = mk_port<bool>();
send(cx, close(p.mk_chan()));
send(cx, quit);
}
assert (y == 10);
}
-fn child(c: _chan[int]) {
+fn child(c: _chan<int>) {
log_err "sending";
send(c, 10);
log_err "value sent"
-}
\ No newline at end of file
+}
-fn main(args: [str]) { log args.(0); }
\ No newline at end of file
+fn main(args: [str]) { log args.(0); }
fn str_byte_len(s: str) -> uint;
fn str_byte_len(s: str) -> uint;
}
-}
\ No newline at end of file
+}
send(ch, 11);
let j = po.recv();
assert (j == 11);
-}
\ No newline at end of file
+}
-fn main() { let v: [mutable int] = ~[mutable ]; }
\ No newline at end of file
+fn main() { let v: [mutable int] = ~[mutable ]; }
export foo;
export main;
-tag list_cell[T] { cons(@list_cell[T]); }
+tag list_cell[T] { cons(@list_cell<T>); }
-fn main() { }
\ No newline at end of file
+fn main() { }
// -*- rust -*-
type compare[T] = fn(@T, @T) -> bool ;
-fn test_generic[T](expected: @T, eq: &compare[T]) {
+fn test_generic[T](expected: @T, eq: &compare<T>) {
let actual: @T = alt true { true { expected } };
assert (eq(expected, actual));
}
test_generic[bool](@true, eq);
}
-fn main() { test_box(); }
\ No newline at end of file
+fn main() { test_box(); }
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare[T]) {
+fn test_generic[T](expected: &T, eq: &compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}
test_generic[@int](@1, eq);
}
-fn main() { test_vec(); }
\ No newline at end of file
+fn main() { test_vec(); }
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare[T]) {
+fn test_generic[T](expected: &T, eq: &compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}
test_generic[t]({a: 1, b: 2}, eq);
}
-fn main() { test_bool(); test_rec(); }
\ No newline at end of file
+fn main() { test_bool(); test_rec(); }
// -*- rust -*-
type compare[T] = fn(@T, @T) -> bool ;
-fn test_generic[T](expected: @T, eq: &compare[T]) {
+fn test_generic[T](expected: @T, eq: &compare<T>) {
let actual: @T = { expected };
assert (eq(expected, actual));
}
test_generic[bool](@true, eq);
}
-fn main() { test_box(); }
\ No newline at end of file
+fn main() { test_box(); }
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare[T]) {
+fn test_generic[T](expected: &T, eq: &compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
test_generic[@int](@1, eq);
}
-fn main() { test_vec(); }
\ No newline at end of file
+fn main() { test_vec(); }
// Tests for standalone blocks as expressions with dynamic type sizes
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, eq: &compare[T]) {
+fn test_generic[T](expected: &T, eq: &compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
test_generic[t]({a: 1, b: 2}, eq);
}
-fn main() { test_bool(); test_rec(); }
\ No newline at end of file
+fn main() { test_bool(); test_rec(); }
test_ret();
test_372();
test_nil();
-}
\ No newline at end of file
+}
// -*- rust -*-
type compare[T] = fn(@T, @T) -> bool ;
-fn test_generic[T](expected: @T, not_expected: @T, eq: &compare[T]) {
+fn test_generic[T](expected: @T, not_expected: @T, eq: &compare<T>) {
let actual: @T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
test_generic[bool](@true, @false, eq);
}
-fn main() { test_box(); }
\ No newline at end of file
+fn main() { test_box(); }
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, not_expected: &T, eq: &compare[T]) {
+fn test_generic[T](expected: &T, not_expected: &T, eq: &compare<T>) {
let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
test_generic[@int](@1, @2, eq);
}
-fn main() { test_vec(); }
\ No newline at end of file
+fn main() { test_vec(); }
// Tests for if as expressions with dynamic type sizes
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](expected: &T, not_expected: &T, eq: &compare[T]) {
+fn test_generic[T](expected: &T, not_expected: &T, eq: &compare<T>) {
let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
test_generic[t]({a: 1, b: 2}, {a: 2, b: 3}, eq);
}
-fn main() { test_bool(); test_rec(); }
\ No newline at end of file
+fn main() { test_bool(); test_rec(); }
iter foo() -> @{a: K} { put @{a: k}; }
}
-fn x(o: &ob[str]) { for each i: @{a: str} in o.foo() { } }
+fn x(o: &ob<str>) { for each i: @{a: str} in o.foo() { } }
fn main() { let o = ob[str]("hi" + "there"); x(o); }
type recbox[T] = {x: @T};
-fn reclift[T](t: &T) -> recbox[T] { ret {x: @t}; }
+fn reclift[T](t: &T) -> recbox<T> { ret {x: @t}; }
fn main() {
let foo: int = 17;
- let rbfoo: recbox[int] = reclift[int](foo);
+ let rbfoo: recbox<int> = reclift[int](foo);
assert (*rbfoo.x == foo);
}
fn main() {
type rgb = {x: u8, y: u8, z: u8};
- let h: handle[rgb] = handle[rgb]({x: 1 as u8, y: 2 as u8, z: 3 as u8});
+ let h: handle<rgb> = handle[rgb]({x: 1 as u8, y: 2 as u8, z: 3 as u8});
log "constructed object";
log h.get().x;
log h.get().y;
assert (h.get().x == 1 as u8);
assert (h.get().y == 2 as u8);
assert (h.get().z == 3 as u8);
-}
\ No newline at end of file
+}
}
fn main() {
- let b: buf[int] = buf[int]({_0: 1, _1: 2, _2: 3});
+ let b: buf<int> = buf[int]({_0: 1, _1: 2, _2: 3});
log "constructed object";
log b.get(0);
log b.get(1);
assert (b.get(1) == 2);
assert (b.get(2) == 3);
b.take2(0);
-}
\ No newline at end of file
+}
-tag list[T] { cons(@T, @list[T]); nil; }
+tag list[T] { cons(@T, @list<T>); nil; }
fn main() {
- let a: list[int] =
+ let a: list<int> =
cons[int](@10, @cons[int](@12, @cons[int](@13, @nil[int])));
-}
\ No newline at end of file
+}
tag foo[T] { arm(T); }
-fn altfoo[T](f: &foo[T]) {
+fn altfoo[T](f: &foo<T>) {
let hit = false;
alt f { arm[T](x) { log "in arm"; hit = true; } }
assert (hit);
}
-fn main() { altfoo[int](arm[int](10)); }
\ No newline at end of file
+fn main() { altfoo[int](arm[int](10)); }
tag noption[T] { some(T); }
fn main() {
- let nop: noption[int] = some[int](5);
+ let nop: noption<int> = some[int](5);
alt nop { some[int](n) { log n; assert (n == 5); } }
- let nop2: noption[{x: int, y: int}] = some({x: 17, y: 42});
+ let nop2: noption<{x: int, y: int}> = some({x: 17, y: 42});
alt nop2 {
some(t) { log t.x; log t.y; assert (t.x == 17); assert (t.y == 42); }
}
-}
\ No newline at end of file
+}
tag option[T] { some(@T); none; }
-fn main() { let a: option[int] = some[int](@10); a = none[int]; }
\ No newline at end of file
+fn main() { let a: option<int> = some[int](@10); a = none[int]; }
type foo[T] = {a: T};
-type bar[T] = foo[T];
+type bar[T] = foo<T>;
-fn takebar[T](b: &bar[T]) { }
+fn takebar[T](b: &bar<T>) { }
-fn main() { }
\ No newline at end of file
+fn main() { }
type pair[T] = {x: T, y: T};
fn main() {
- let x: pair[int] = {x: 10, y: 12};
+ let x: pair<int> = {x: 10, y: 12};
assert (x.x == 10);
assert (x.y == 12);
-}
\ No newline at end of file
+}
type mapper = fn(str, putter) ;
- tag ctrl_proto { find_reducer([u8], _chan[int]); mapper_done; }
+ tag ctrl_proto { find_reducer([u8], _chan<int>); mapper_done; }
- fn start_mappers(ctrl: _chan[ctrl_proto], inputs: &[str]) {
+ fn start_mappers(ctrl: _chan<ctrl_proto>, inputs: &[str]) {
for i: str in inputs { task::_spawn(bind map_task(ctrl, i)); }
}
- fn map_task(ctrl: _chan[ctrl_proto], input: str) {
+ fn map_task(ctrl: _chan<ctrl_proto>, input: str) {
let intermediates = map::new_str_hash();
- fn emit(im: &map::hashmap[str, int], ctrl: _chan[ctrl_proto],
+ fn emit(im: &map::hashmap<str, int>, ctrl: _chan<ctrl_proto>,
key: str, val: str) {
let c;
alt im.find(key) {
}
fn map_reduce(inputs: &[str]) {
- let ctrl = mk_port[ctrl_proto]();
+ let ctrl = mk_port<ctrl_proto>();
// This task becomes the master control task. It spawns others
// to do the rest.
- let reducers: map::hashmap[str, int];
+ let reducers: map::hashmap<str, int>;
reducers = map::new_str_hash();
fn bar() { log "bar"; }
}
-fn main(args: [str]) { let zed = 42; bar(); }
\ No newline at end of file
+fn main(args: [str]) { let zed = 42; bar(); }
}
}
-fn main(args: [str]) { bar(); }
\ No newline at end of file
+fn main(args: [str]) { bar(); }
mod zed { }
}
}
-fn main(args: [str]) { baz(); }
\ No newline at end of file
+fn main(args: [str]) { baz(); }
assert (s.(3u32) == 'd' as u8);
assert (s.(3i32) == 'd' as u8);
log s.(3u8);
-}
\ No newline at end of file
+}
import std::comm::_chan;
import std::comm::send;
-fn grandchild(c: _chan[int]) { send(c, 42); }
+fn grandchild(c: _chan<int>) { send(c, 42); }
-fn child(c: _chan[int]) {
+fn child(c: _chan<int>) {
let _grandchild = task::_spawn(bind grandchild(c));
join_id(_grandchild);
}
assert (x == 42);
join_id(_child);
-}
\ No newline at end of file
+}
tag msg { closed; received([u8]); }
-fn producer(c: _chan[[u8]]) {
+fn producer(c: _chan<[u8]>) {
send(c, ~[1u8, 2u8, 3u8, 4u8]);
let empty: [u8] = ~[];
send(c, empty);
}
-fn packager(cb: _chan[_chan[[u8]]], msg: _chan[msg]) {
- let p: _port[[u8]] = mk_port();
+fn packager(cb: _chan<_chan<[u8]>>, msg: _chan<msg>) {
+ let p: _port<[u8]> = mk_port();
send(cb, p.mk_chan());
while true {
log "waiting for bytes";
}
fn main() {
- let p: _port[msg] = mk_port();
- let recv_reader: _port[_chan[[u8]]] = mk_port();
+ let p: _port<msg> = mk_port();
+ let recv_reader: _port<_chan<[u8]>> = mk_port();
let pack = task::_spawn(bind packager(recv_reader.mk_chan(),
p.mk_chan()));
- let source_chan: _chan[[u8]] = recv_reader.recv();
+ let source_chan: _chan<[u8]> = recv_reader.recv();
let prod = task::_spawn(bind producer(source_chan));
while true {
import std::comm::mk_port;
import std::comm::send;
-fn producer(c: _chan[[u8]]) {
+fn producer(c: _chan<[u8]>) {
send(c, ~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8,
8u8, 9u8, 10u8, 11u8, 12u8, 13u8 ]);
}
fn main() {
- let p: _port[[u8]] = mk_port();
+ let p: _port<[u8]> = mk_port();
let prod = task::_spawn(bind producer(p.mk_chan()));
let data: [u8] = p.recv();
assert (y == 10);
}
-fn child(c: _chan[int]) { send(c, 10); }
\ No newline at end of file
+fn child(c: _chan<int>) { send(c, 10); }
import std::task;
import std::comm;
-fn sub(parent: comm::_chan[int], id: int) {
+fn sub(parent: comm::_chan<int>, id: int) {
if (id == 0) {
comm::send(parent, 0);
} else {
fn f() -> [int] { vec::init_elt(0, 1u) }
}
-fn main() { let x = m::f(); }
\ No newline at end of file
+fn main() { let x = m::f(); }
let len = std::vec::len[int](v);
log len;
assert (len == 3 as uint);
-}
\ No newline at end of file
+}
// This just tests whether the vec leaks its members.
let pvec: [mutable @{a: int, b: int}] =
~[mutable @{a: 1, b: 2}, @{a: 3, b: 4}, @{a: 5, b: 6}];
-}
\ No newline at end of file
+}
native "cdecl" mod baz = "" { }
-fn main(args: [str]) { }
\ No newline at end of file
+fn main(args: [str]) { }
import std::option::some;
import std::option::none;
-tag t { foo(int, uint); bar(int, option::t[int]); }
+tag t { foo(int, uint); bar(int, option::t<int>); }
fn nested(o: t) {
alt o {
}
}
-fn main() { nested(bar(1, none[int])); }
\ No newline at end of file
+fn main() { nested(bar(1, none[int])); }
tag myvec[X] = [X];
-fn myvec_deref[X](mv: &myvec[X]) -> [X] { ret *mv; }
+fn myvec_deref[X](mv: &myvec<X>) -> [X] { ret *mv; }
-fn myvec_elt[X](mv: &myvec[X]) -> X { ret mv.(0); }
+fn myvec_elt[X](mv: &myvec<X>) -> X { ret mv.(0); }
fn main() {
let mv = myvec(~[1, 2, 3]);
assert (myvec_deref(mv).(1) == 2);
assert (myvec_elt(mv) == 1);
assert (mv.(2) == 3);
-}
\ No newline at end of file
+}
}
}
- obj sender(c: _chan[int]) {
+ obj sender(c: _chan<int>) {
fn take(z: int) {
send(c, z);
}
// -*- rust -*-
tag clam[T] { signed(int); unsigned(uint); }
-fn getclam[T]() -> clam[T] { ret signed[T](42); }
+fn getclam[T]() -> clam<T> { ret signed[T](42); }
obj impatience[T]() {
- fn moreclam() -> clam[T] { be getclam[T](); }
+ fn moreclam() -> clam<T> { be getclam[T](); }
}
-fn main() { }
\ No newline at end of file
+fn main() { }
let b = buf(~[1 as u8, 2 as u8, 3 as u8]);
log b.get(1);
assert (b.get(1) == 2 as u8);
-}
\ No newline at end of file
+}
fn bar(offset: uint) { }
}
-fn main(args: [str]) { foo::bar(0u); }
\ No newline at end of file
+fn main(args: [str]) { foo::bar(0u); }
// xfail-stage3
// This checks that preemption works.
-fn starve_main(alive: chan[int]) {
+fn starve_main(alive: chan<int>) {
log "signalling main";
alive <| 1;
log "starving main";
}
fn main() {
- let alive: port[int] = port();
+ let alive: port<int> = port();
log "main started";
let s: task = spawn starve_main(chan(alive));
let i: int;
log "main got alive signal";
while i < 50 { log "main iterated"; i += 1; }
log "main completed";
-}
\ No newline at end of file
+}
tag option[T] { none; some(T); }
-fn sink(res: option[close_res]) {}
+fn sink(res: option<close_res>) {}
fn main() {
let c = @mutable true;
tag option[T] { none; some(T); }
-fn f[T]() -> option[T] { ret none; }
+fn f[T]() -> option<T> { ret none; }
-fn main() { f[int](); }
\ No newline at end of file
+fn main() { f[int](); }
// Dump lots of items into the channel so it has to grow.
// Don't trigger any assertions.
fn test_grow() {
- let myport: comm::_port[record] = comm::mk_port();
+ let myport: comm::_port<record> = comm::mk_port();
let mychan = myport.mk_chan();
for each i: uint in uint::range(0u, 100u) {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
// tests that ctrl's type gets inferred properly
type command[K, V] = {key: K, val: V};
-fn cache_server[K, V](c: _chan[_chan[command[K, V]]]) {
- let ctrl = mk_port[_chan[command[K, V]]]();
+fn cache_server[K, V](c: _chan<_chan<command<K, V>>>) {
+ let ctrl = mk_port[_chan<command<K, V>>]();
send(c, ctrl.mk_chan());
}
-fn main() { }
\ No newline at end of file
+fn main() { }
// -*- rust -*-
tag clam[T] { a(T, int); b; }
-fn uhoh[T](v: &[clam[T]]) {
+fn uhoh[T](v: &[clam<T>]) {
alt v.(1) {
a[T](t, u) { log "incorrect"; log u; fail; }
b[T]. { log "correct"; }
}
fn main() {
- let v: [clam[int]] = ~[b[int], b[int], a[int](42, 17)];
+ let v: [clam<int>] = ~[b[int], b[int], a[int](42, 17)];
uhoh[int](v);
-}
\ No newline at end of file
+}
import std::comm;
import std::task;
-type ctx = comm::_chan[int];
+type ctx = comm::_chan<int>;
fn iotask(cx: ctx, ip: str) { assert (str::eq(ip, "localhost")); }
fn main() {
- let p = comm::mk_port[int]();
+ let p = comm::mk_port<int>();
task::_spawn(bind iotask(p.mk_chan(), "localhost"));
}
n <-> a.(0);
assert (a.(0) == 42);
assert (n == 0);
-}
\ No newline at end of file
+}
fn baz() { zed(nil); }
}
-fn main(args: [str]) { }
\ No newline at end of file
+fn main(args: [str]) { }
fn main() { test05(); }
-fn test05_start(ch : _chan[int]) {
+fn test05_start(ch : _chan<int>) {
log_err ch;
send(ch, 10);
log_err "sent 10";
}
fn test05() {
- let po = comm::mk_port[int]();
+ let po = comm::mk_port<int>();
let ch = po.mk_chan();
task::_spawn(bind test05_start(ch));
let value = po.recv();
import std::task;
import std::comm;
-fn start(c: comm::_chan[str]) {
- let p = comm::mk_port[str]();
+fn start(c: comm::_chan<str>) {
+ let p = comm::mk_port<str>();
c.send(p.mk_chan().unsafe_ptr());
let a;
import std::comm;
import std::task;
-fn start(c: comm::_chan[comm::_chan[int]]) {
- let p : comm::_port[int] = comm::mk_port();
+fn start(c: comm::_chan<comm::_chan<int>>) {
+ let p : comm::_port<int> = comm::mk_port();
comm::send(c, p.mk_chan());
}
fn main() {
- let p = comm::mk_port[comm::_chan[int]]();
+ let p = comm::mk_port<comm::_chan<int>>();
let child = task::_spawn(bind start(p.mk_chan()));
let c = p.recv();
}
import std::comm;
import std::comm::send;
-fn start(c: comm::_chan[int], start: int, number_of_messages: int) {
+fn start(c: comm::_chan<int>, start: int, number_of_messages: int) {
let i: int = 0;
while i < number_of_messages { send(c, start + i); i += 1; }
}
fn main() {
log "Check that we don't deadlock.";
- let p : comm::_port[int] = comm::mk_port();
+ let p : comm::_port<int> = comm::mk_port();
let a = task::_spawn(bind start(p.mk_chan(), 0, 10));
task::join_id(a);
log "Joined task";
import std::comm;
import std::task;
-fn start(c : comm::_chan[int], n: int) {
+fn start(c : comm::_chan<int>, n: int) {
let i: int = n;
while i > 0 { comm::send(c, 0); i = i - 1; }
}
fn main() {
- let p = comm::mk_port[comm::_chan[int]]();
+ let p = comm::mk_port<comm::_chan<int>>();
// Spawn a task that sends us back messages. The parent task
// is likely to terminate before the child completes, so from
// the child's point of view the receiver may die. We should
// drop messages on the floor in this case, and not crash!
let child = task::_spawn(bind start(p.mk_chan(), 10));
let c = p.recv();
-}
\ No newline at end of file
+}
fn main() { log "===== WITHOUT THREADS ====="; test00(); }
-fn test00_start(ch: _chan[int], message: int, count: int) {
+fn test00_start(ch: _chan<int>, message: int, count: int) {
log "Starting test00_start";
let i: int = 0;
while i < count {
fn main() { test00(); }
-fn test00_start(c: comm::_chan[int], start: int, number_of_messages: int) {
+fn test00_start(c: comm::_chan<int>, start: int, number_of_messages: int) {
let i: int = 0;
while i < number_of_messages { comm::send(c, start + i); i += 1; }
}
task::join_id(t3);
assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2);
-}
\ No newline at end of file
+}
fn main() { test00(); }
-fn test00_start(c : comm::_chan[int], start: int, number_of_messages: int) {
+fn test00_start(c : comm::_chan<int>, start: int, number_of_messages: int) {
let i: int = 0;
while i < number_of_messages { comm::send(c, start + i); i += 1; }
}
task::join_id(t3);
assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2);
-}
\ No newline at end of file
+}
fn main() { test00(); }
-fn test00_start(c: comm::_chan[int], number_of_messages: int) {
+fn test00_start(c: comm::_chan<int>, number_of_messages: int) {
let i: int = 0;
while i < number_of_messages { comm::send(c, i+0); i += 1; }
}
// any size, but rustc currently can because they do have size. Whether
// or not this is desirable I don't know, but here's a regression test.
fn main() {
- let po: comm::_port[()] = comm::mk_port();
- let ch: comm::_chan[()] = po.mk_chan();
+ let po: comm::_port<()> = comm::mk_port();
+ let ch: comm::_chan<()> = po.mk_chan();
comm::send(ch, ());
let n: () = po.recv();
assert (n == ());
-}
\ No newline at end of file
+}
test06();
}
-fn test00_start(ch: _chan[int], message: int, count: int) {
+fn test00_start(ch: _chan<int>, message: int, count: int) {
log "Starting test00_start";
let i: int = 0;
while i < count { log "Sending Message"; send(ch, message+0); i = i + 1; }
log "Finishing up.";
}
-fn test05_start(ch: _chan[int]) {
+fn test05_start(ch: _chan<int>) {
send(ch, 10);
send(ch, 20);
send(ch, 30);
let p1;
let p2;
- p1 = comm::mk_port[int]();
- p2 = comm::mk_port[int]();
+ p1 = comm::mk_port<int>();
+ p2 = comm::mk_port<int>();
assert (p1 == p1);
assert (p1 != p2);
join_id(t1);
join_id(t2);
-}
\ No newline at end of file
+}
send(ch, 42);
let r = po.recv();
log_err r;
-}
\ No newline at end of file
+}
type lteq[T] = fn(&T) -> bool ;
-fn main(args: [str]) { }
\ No newline at end of file
+fn main(args: [str]) { }
fn g(a: *int) -> *int { let b = f(a); ret b; }
-fn main(args: [str]) { ret; }
\ No newline at end of file
+fn main(args: [str]) { ret; }
-fn foo[T](o: &myoption[T]) -> int {
+fn foo[T](o: &myoption<T>) -> int {
let x: int = 5;
alt o { none[T]. { } some[T](t) { x += 1; } }
ret x;
tag myoption[T] { none; some(T); }
-fn main() { log 5; }
\ No newline at end of file
+fn main() { log 5; }
-fn foo[T](o: &myoption[T]) -> int {
+fn foo[T](o: &myoption<T>) -> int {
let x: int;
alt o { none[T]. { fail; } some[T](t) { x = 5; } }
ret x;
tag myoption[T] { none; some(T); }
-fn main() { log 5; }
\ No newline at end of file
+fn main() { log 5; }
assert (str::shift_char(stack) == '×');
str::unshift_char(stack, 'ß');
assert (str::eq(stack, "ßu"));
-}
\ No newline at end of file
+}
assert (str::refcount(s) == const_refcount);
}
-fn main() { fast_growth(); slow_growth(); slow_growth2(); }
\ No newline at end of file
+fn main() { fast_growth(); slow_growth(); slow_growth2(); }
assert (v.(0) == 1);
assert (v.(7) == 8);
assert (v.(9) == 0);
-}
\ No newline at end of file
+}
let pvec: [@{x: int, y: int}] =
~[@{x: 1, y: 2}, @{x: 3, y: 4}, @{x: 5, y: 6}];
-}
\ No newline at end of file
+}
let later: [int];
if true { later = ~[1]; } else { later = ~[2]; }
log later.(0);
-}
\ No newline at end of file
+}
fn push[T](v: &mutable [mutable? T], t: &T) { v += ~[t]; }
-fn main() { let v = ~[1, 2, 3]; push(v, 1); }
\ No newline at end of file
+fn main() { let v = ~[1, 2, 3]; push(v, 1); }
i -= 1;
expected_len *= 2u;
}
-}
\ No newline at end of file
+}
// xfail-stage2
// xfail-stage3
fn main() {
- let vec[int] v = [1,2,3,4,5];
+ let vec<int> v = [1,2,3,4,5];
auto v2 = v.(1,2);
assert (v2.(0) == 2);
assert (v2.(1) == 3);
-}
\ No newline at end of file
+}
x = x + 1;
assert (v.(x) == 20);
assert (v.(x - 1) == 10);
-}
\ No newline at end of file
+}
-fn main() { let quux: @[uint] = @~[]; }
\ No newline at end of file
+fn main() { let quux: @[uint] = @~[]; }
}
}
assert (i == 95);
-}
\ No newline at end of file
+}
#[test]
fn create_port_and_chan() {
- let p = comm::mk_port[int]();
+ let p = comm::mk_port<int>();
let c = p.mk_chan();
}
#[test]
fn send_recv() {
- let p = comm::mk_port[int]();
+ let p = comm::mk_port<int>();
let c = p.mk_chan();
comm::send(c, 42);
#[test]
fn test_simple() {
- let d: deque::t[int] = deque::create[int]();
+ let d: deque::t<int> = deque::create[int]();
assert (d.size() == 0u);
d.add_front(17);
d.add_front(42);
}
fn test_boxes(a: @int, b: @int, c: @int, d: @int) {
- let deq: deque::t[@int] = deque::create[@int]();
+ let deq: deque::t<@int> = deque::create[@int]();
assert (deq.size() == 0u);
deq.add_front(a);
deq.add_front(b);
type eqfn[T] = fn(&T, &T) -> bool ;
-fn test_parameterized[@T](e: eqfn[T], a: &T, b: &T, c: &T, d: &T) {
- let deq: deque::t[T] = deque::create[T]();
+fn test_parameterized[@T](e: eqfn<T>, a: &T, b: &T, c: &T, d: &T) {
+ let deq: deque::t<T> = deque::create[T]();
assert (deq.size() == 0u);
deq.add_front(a);
deq.add_front(b);
}
}
}
- fn taggypareq[@T](a: &taggypar[T], b: &taggypar[T]) -> bool {
+ fn taggypareq[@T](a: &taggypar<T>, b: &taggypar<T>) -> bool {
alt a {
onepar[T](a1) {
alt b { onepar[T](b1) { ret a1 == b1; } _ { ret false; } }
test_boxes(@5, @72, @64, @175);
log "*** end test boxes";
log "test parameterized: int";
- let eq1: eqfn[int] = inteq;
+ let eq1: eqfn<int> = inteq;
test_parameterized[int](eq1, 5, 72, 64, 175);
log "*** test parameterized: @int";
- let eq2: eqfn[@int] = intboxeq;
+ let eq2: eqfn<@int> = intboxeq;
test_parameterized[@int](eq2, @5, @72, @64, @175);
log "*** end test parameterized @int";
log "test parameterized: taggy";
- let eq3: eqfn[taggy] = taggyeq;
+ let eq3: eqfn<taggy> = taggyeq;
test_parameterized[taggy](eq3, one(1), two(1, 2), three(1, 2, 3),
two(17, 42));
- log "*** test parameterized: taggypar[int]";
- let eq4: eqfn[taggypar[int]] = taggypareq[int];
- test_parameterized[taggypar[int]](eq4,
+ log "*** test parameterized: taggypar<int>";
+ let eq4: eqfn<taggypar<int>> = taggypareq[int];
+ test_parameterized[taggypar<int>](eq4,
onepar[int](1),
twopar[int](1, 2),
threepar[int](1, 2, 3),
let reccy2: reccy = {x: 345, y: 2, t: two(1, 2)};
let reccy3: reccy = {x: 1, y: 777, t: three(1, 2, 3)};
let reccy4: reccy = {x: 19, y: 252, t: two(17, 42)};
- let eq5: eqfn[reccy] = reccyeq;
+ let eq5: eqfn<reccy> = reccyeq;
test_parameterized[reccy](eq5, reccy1, reccy2, reccy3, reccy4);
log "*** end test parameterized: reccy";
log "*** done";
#[test]
fn test_lefts_none() {
- let input: [t[int, int]] = ~[right(10), right(10)];
+ let input: [t<int, int>] = ~[right(10), right(10)];
let result = lefts(input);
assert (len(result) == 0u);
}
#[test]
fn test_lefts_empty() {
- let input: [t[int, int]] = ~[];
+ let input: [t<int, int>] = ~[];
let result = lefts(input);
assert (len(result) == 0u);
}
#[test]
fn test_rights_none() {
- let input: [t[int, int]] = ~[left(10), left(10)];
+ let input: [t<int, int>] = ~[left(10), left(10)];
let result = rights(input);
assert (len(result) == 0u);
}
#[test]
fn test_rights_empty() {
- let input: [t[int, int]] = ~[];
+ let input: [t<int, int>] = ~[];
let result = rights(input);
assert (len(result) == 0u);
}
#[test]
fn test_partition_no_lefts() {
- let input: [t[int, int]] = ~[right(10), right(11)];
+ let input: [t<int, int>] = ~[right(10), right(11)];
let result = partition(input);
assert (len(result.lefts) == 0u);
assert (len(result.rights) == 2u);
#[test]
fn test_partition_no_rights() {
- let input: [t[int, int]] = ~[left(10), left(11)];
+ let input: [t<int, int>] = ~[left(10), left(11)];
let result = partition(input);
assert (len(result.lefts) == 2u);
assert (len(result.rights) == 0u);
#[test]
fn test_partition_empty() {
- let input: [t[int, int]] = ~[];
+ let input: [t<int, int>] = ~[];
let result = partition(input);
assert (len(result.lefts) == 0u);
assert (len(result.rights) == 0u);
#[test]
fn test_find_success() {
let l = from_vec(~[0, 1, 2]);
- fn match(i: &int) -> option::t[int] {
+ fn match(i: &int) -> option::t<int> {
ret if i == 2 { option::some(i) } else { option::none[int] };
}
let rs = list::find(l, match);
#[test]
fn test_find_fail() {
let l = from_vec(~[0, 1, 2]);
- fn match(i: &int) -> option::t[int] { ret option::none[int]; }
+ fn match(i: &int) -> option::t<int> { ret option::none[int]; }
let rs = list::find(l, match);
assert (rs == option::none[int]);
}
ret u;
}
- let hasher_uint: map::hashfn[uint] = hash_uint;
- let eqer_uint: map::eqfn[uint] = eq_uint;
- let hasher_str: map::hashfn[str] = str::hash;
- let eqer_str: map::eqfn[str] = str::eq;
+ let hasher_uint: map::hashfn<uint> = hash_uint;
+ let eqer_uint: map::eqfn<uint> = eq_uint;
+ let hasher_str: map::hashfn<str> = str::hash;
+ let eqer_str: map::eqfn<str> = str::eq;
log "uint -> uint";
- let hm_uu: map::hashmap[uint, uint] =
+ let hm_uu: map::hashmap<uint, uint> =
map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
assert (hm_uu.insert(10u, 12u));
assert (hm_uu.insert(11u, 13u));
let eleven: str = "eleven";
let twelve: str = "twelve";
log "str -> uint";
- let hm_su: map::hashmap[str, uint] =
+ let hm_su: map::hashmap<str, uint> =
map::mk_hashmap[str, uint](hasher_str, eqer_str);
assert (hm_su.insert("ten", 12u));
assert (hm_su.insert(eleven, 13u));
assert (!hm_su.insert("twelve", 12u));
assert (hm_su.get("twelve") == 12u);
log "uint -> str";
- let hm_us: map::hashmap[uint, str] =
+ let hm_us: map::hashmap<uint, str> =
map::mk_hashmap[uint, str](hasher_uint, eqer_uint);
assert (hm_us.insert(10u, "twelve"));
assert (hm_us.insert(11u, "thirteen"));
assert (!hm_us.insert(12u, "twelve"));
assert (str::eq(hm_us.get(12u), "twelve"));
log "str -> str";
- let hm_ss: map::hashmap[str, str] =
+ let hm_ss: map::hashmap<str, str> =
map::mk_hashmap[str, str](hasher_str, eqer_str);
assert (hm_ss.insert(ten, "twelve"));
assert (hm_ss.insert(eleven, "thirteen"));
ret u;
}
log "uint -> uint";
- let hasher_uint: map::hashfn[uint] = hash_uint;
- let eqer_uint: map::eqfn[uint] = eq_uint;
- let hm_uu: map::hashmap[uint, uint] =
+ let hasher_uint: map::hashfn<uint> = hash_uint;
+ let eqer_uint: map::eqfn<uint> = eq_uint;
+ let hm_uu: map::hashmap<uint, uint> =
map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
let i: uint = 0u;
while i < num_to_insert {
i += 1u;
}
log "str -> str";
- let hasher_str: map::hashfn[str] = str::hash;
- let eqer_str: map::eqfn[str] = str::eq;
- let hm_ss: map::hashmap[str, str] =
+ let hasher_str: map::hashfn<str> = str::hash;
+ let eqer_str: map::eqfn<str> = str::eq;
+ let hm_ss: map::hashmap<str, str> =
map::mk_hashmap[str, str](hasher_str, eqer_str);
i = 0u;
while i < num_to_insert {
assert (hash(0u) == hash(1u));
assert (hash(2u) == hash(3u));
assert (hash(0u) != hash(2u));
- let hasher: map::hashfn[uint] = hash;
- let eqer: map::eqfn[uint] = eq;
- let hm: map::hashmap[uint, uint] =
+ let hasher: map::hashfn<uint> = hash;
+ let eqer: map::eqfn<uint> = eq;
+ let hm: map::hashmap<uint, uint> =
map::mk_hashmap[uint, uint](hasher, eqer);
let i: uint = 0u;
while i < num_to_insert {
* FIXME (issue #150): we want to check the removed value as in the
* following:
- let util.option[uint] v = hm.remove(i);
+ let v: util.option<uint> = hm.remove(i);
alt (v) {
case (util.some[uint](u)) {
assert (u == (i * i));
assert (std::option::is_none(map.find(key)));
map.insert(key, "val");
assert (std::option::get(map.find(key)) == "val");
-}
\ No newline at end of file
+}
pred is_three(n: &uint) -> bool { ret n == 3u; }
-fn square_if_odd(n: &uint) -> option::t[uint] {
+fn square_if_odd(n: &uint) -> option::t<uint> {
ret if n % 2u == 1u { some(n * n) } else { none };
}
assert (w.(1) == 9u);
assert (w.(2) == 25u);
- fn halve(i: &int) -> option::t[int] {
+ fn halve(i: &int) -> option::t<int> {
if i % 2 == 0 {
ret option::some[int](i / 2);
} else { ret option::none[int]; }
}
log "refcnt is";
log str::refcount(s1);
-}
\ No newline at end of file
+}