} else { be bisect(v, mid, hi, target); }
} else { ret v.(hi).ch; }
}
- ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r);
+ ret bisect(genelist, 0u, vec::len::<aminoacids>(genelist) - 1u, r);
}
fn make_random_fasta(id: str, desc: str, genelist: &[aminoacids], n: int) {
} 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));
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();
}
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.
// error-pattern: expecting
fn main() {
- let x.y[int].z foo;
+ let x.y::<int>.z foo;
}
// error-pattern:mismatched types
// From Issue #778
tag clam<T> { a(T); }
-fn main() { let c; c = a(c); alt c { a[int](_) { } } }
+fn main() { let c; c = a(c); alt c { a::<int>(_) { } } }
tag bar { t1((), option::t<[int]>); t2; }
-fn foo(t: bar) { alt t { t1(_, some[int](x)) { log x; } _ { fail; } } }
+fn foo(t: bar) { alt t { t1(_, some::<int>(x)) { log x; } _ { fail; } } }
fn main() { }
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);
fn run(handle: &handle, lib_path: &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),
fn foo(s: str) { }
fn main() {
- let i = alt some[int](3) { none[int]. { fail } some[int](_) { fail } };
+ let i = alt some::<int>(3) {
+ none::<int>. { fail }
+ some::<int>(_) { fail }
+ };
foo(i);
-}
\ No newline at end of file
+}
fn child() { assert (1 == 2); }
fn main() {
- let p = mk_port[int]();
+ let p = mk_port::<int>();
task::_spawn(bind child());
let x = p.recv();
}
fn echo<~T>(c: _chan<T>, oc: _chan<_chan<T>>) {
// Tests that the type argument in port gets
// visited
- let p = mk_port[T]();
+ let p = mk_port::<T>();
send(oc, p.mk_chan());
let x = p.recv();
ret {struct: st, cname: cname, hash: 0u};
}
-fn main() { mk_raw_ty(ty_nil, none[str]); }
+fn main() { mk_raw_ty(ty_nil, none::<str>); }
import std::option::*;
fn main() {
- let i: int = alt some[int](3) { none[int]. { fail } some[int](_) { 5 } };
+ let i: int = alt some::<int>(3) {
+ none::<int>. { fail }
+ some::<int>(_) { 5 }
+ };
log i;
-}
\ No newline at end of file
+}
entire if expression */
if true {
- } else { alt y { none[T]. { x = 17; } _ { x = 42; } } rs += ~[x]; }
+ } else { alt y { none::<T>. { x = 17; } _ { x = 42; } } rs += ~[x]; }
ret;
}
-fn main() { log "hello"; foo[int](some[int](5)); }
+fn main() { log "hello"; foo::<int>(some::<int>(5)); }
}
fn test_port() {
- let p1 = comm::mk_port[int]();
- let p2 = comm::mk_port[int]();
+ let p1 = comm::mk_port::<int>();
+ let p2 = comm::mk_port::<int>();
assert p1 == p1;
assert p1 != p2;
let foo: int = 17;
let bfoo: box<int> = {c: @foo};
log "see what's in our box";
- assert (unbox[int](bfoo) == foo);
+ assert (unbox::<int>(bfoo) == foo);
}
fn main() {
let cx = new();
- let p = mk_port<bool>();
+ let p = mk_port::<bool>();
send(cx, close(p.mk_chan()));
send(cx, quit);
}
fn f<T>(i: @int, t: &T) { }
-fn main() { let x = bind f[char](@0xdeafbeef, _); }
+fn main() { let x = bind f::<char>(@0xdeafbeef, _); }
fn test_box() {
fn compare_box(b1: @bool, b2: @bool) -> bool { ret *b1 == *b2; }
let eq = bind compare_box(_, _);
- test_generic[bool](@true, eq);
+ test_generic::<bool>(@true, eq);
}
fn main() { test_box(); }
fn test_vec() {
fn compare_box(v1: &@int, v2: &@int) -> bool { ret v1 == v2; }
let eq = bind compare_box(_, _);
- test_generic[@int](@1, eq);
+ test_generic::<@int>(@1, eq);
}
fn main() { test_vec(); }
fn test_bool() {
fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; }
let eq = bind compare_bool(_, _);
- test_generic[bool](true, eq);
+ test_generic::<bool>(true, eq);
}
fn test_rec() {
fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; }
let eq = bind compare_rec(_, _);
- test_generic[t]({a: 1, b: 2}, eq);
+ test_generic::<t>({a: 1, b: 2}, eq);
}
fn main() { test_bool(); test_rec(); }
ret *b1 == *b2;
}
let eq = bind compare_box(_, _);
- test_generic[bool](@true, eq);
+ test_generic::<bool>(@true, eq);
}
fn main() { test_box(); }
fn test_vec() {
fn compare_vec(v1: &@int, v2: &@int) -> bool { ret v1 == v2; }
let eq = bind compare_vec(_, _);
- test_generic[@int](@1, eq);
+ test_generic::<@int>(@1, eq);
}
fn main() { test_vec(); }
fn test_bool() {
fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; }
let eq = bind compare_bool(_, _);
- test_generic[bool](true, eq);
+ test_generic::<bool>(true, eq);
}
fn test_rec() {
fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; }
let eq = bind compare_rec(_, _);
- test_generic[t]({a: 1, b: 2}, eq);
+ test_generic::<t>({a: 1, b: 2}, eq);
}
fn main() { test_bool(); test_rec(); }
fn test_box() {
fn compare_box(b1: @bool, b2: @bool) -> bool { ret *b1 == *b2; }
let eq = bind compare_box(_, _);
- test_generic[bool](@true, @false, eq);
+ test_generic::<bool>(@true, @false, eq);
}
fn main() { test_box(); }
fn test_vec() {
fn compare_box(v1: &@int, v2: &@int) -> bool { ret v1 == v2; }
let eq = bind compare_box(_, _);
- test_generic[@int](@1, @2, eq);
+ test_generic::<@int>(@1, @2, eq);
}
fn main() { test_vec(); }
fn test_bool() {
fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; }
let eq = bind compare_bool(_, _);
- test_generic[bool](true, false, eq);
+ test_generic::<bool>(true, false, eq);
}
fn test_rec() {
fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; }
let eq = bind compare_rec(_, _);
- test_generic[t]({a: 1, b: 2}, {a: 2, b: 3}, eq);
+ test_generic::<t>({a: 1, b: 2}, {a: 2, b: 3}, eq);
}
fn main() { test_bool(); test_rec(); }
fn x(o: &ob<str>) { for each i: @{a: str} in o.foo() { } }
-fn main() { let o = ob[str]("hi" + "there"); x(o); }
+fn main() { let o = ob::<str>("hi" + "there"); x(o); }
fn main() {
let expected = @100;
- let actual = id[@int](expected);
+ let actual = id::<@int>(expected);
log *actual;
assert (*expected == *actual);
}
let t = {_0: 1, _1: 2, _2: 3, _3: 4, _4: 5, _5: 6, _6: 7};
assert (t._5 == 6);
let f1 =
- bind id[{_0: int,
- _1: int,
- _2: int,
- _3: int,
- _4: int,
- _5: int,
- _6: int}](_);
+ bind id::<{_0: int,
+ _1: int,
+ _2: int,
+ _3: int,
+ _4: int,
+ _5: int,
+ _6: int}>(_);
assert (f1(t)._5 == 6);
}
fn box<T>(x: &{x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; }
fn main() {
- let x: @{x: int, y: int, z: int} = box[int]({x: 1, y: 2, z: 3});
+ let x: @{x: int, y: int, z: int} = box::<int>({x: 1, y: 2, z: 3});
assert (x.y == 2);
}
type pair = {a: T, b: T};
let x: pair = {a: t, b: t};
- ret g[pair](x);
+ ret g::<pair>(x);
}
fn main() {
- let b = f[int](10);
+ let b = f::<int>(10);
log b.a;
log b.b;
assert (b.a == 10);
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 foo<T>() { }
}
-fn main() { foomod::foo[int](); foomod::foo[int](); }
+fn main() { foomod::foo::<int>(); foomod::foo::<int>(); }
let b = 'b';
let p: triple = {x: 65, y: 66, z: 67};
let q: triple = {x: 68, y: 69, z: 70};
- y = id[int](x);
+ y = id::<int>(x);
log y;
assert (x == y);
- b = id[char](a);
+ b = id::<char>(a);
log b;
assert (a == b);
- q = id[triple](p);
+ q = id::<triple>(p);
x = p.z;
y = q.z;
log y;
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;
}
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);
fn main() {
let a: list<int> =
- cons[int](@10, @cons[int](@12, @cons[int](@13, @nil[int])));
+ cons::<int>(@10, @cons::<int>(@12, @cons::<int>(@13, @nil::<int>)));
}
fn altfoo<T>(f: &foo<T>) {
let hit = false;
- alt f { arm[T](x) { log "in arm"; hit = true; } }
+ alt f { arm::<T>(x) { log "in arm"; hit = true; } }
assert (hit);
}
-fn main() { altfoo[int](arm[int](10)); }
+fn main() { altfoo::<int>(arm::<int>(10)); }
tag noption<T> { some(T); }
fn main() {
- let nop: noption<int> = some[int](5);
- alt nop { some[int](n) { log n; assert (n == 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});
alt nop2 {
some(t) { log t.x; log t.y; assert (t.x == 17); assert (t.y == 42); }
tag option<T> { some(@T); none; }
-fn main() { let a: option<int> = some[int](@10); a = none[int]; }
+fn main() { let a: option<int> = some::<int>(@10); a = none::<int>; }
fn main() {
let produce: fn() -> int = mk;
let consume: fn(&int) = chk;
- apply[int](produce, consume);
+ apply::<int>(produce, consume);
}
}
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 v = init_elt(0, 0u);
v += ~[4, 2];
assert (reversed(v) == ~[2, 4]);
-}
\ No newline at end of file
+}
-fn quux<T>(x: &T) -> T { let f = id[T]; ret f(x); }
+fn quux<T>(x: &T) -> T { let f = id::<T>; ret f(x); }
fn id<T>(x: &T) -> T { ret x; }
closed. { log "Got close message"; break; }
received(data) {
log "Got data. Length is:";
- log vec::len[u8](data);
+ log vec::len::<u8>(data);
}
}
}
fn leaky<T>(t: &T) { }
-fn main() { let x = @10; leaky[@int](x); }
+fn main() { let x = @10; leaky::<@int>(x); }
grow(v);
grow(v);
grow(v);
- let len = std::vec::len[int](v);
+ let len = std::vec::len::<int>(v);
log len;
assert (len == 3 as uint);
}
fn baz() -> ! { fail; }
fn foo() {
- alt some[int](5) {
- some[int](x) {
+ alt some::<int>(5) {
+ some::<int>(x) {
let bar;
- alt none[int] { none[int]. { bar = 5; } _ { baz(); } }
+ alt none::<int> { none::<int>. { bar = 5; } _ { baz(); } }
log bar;
}
- none[int]. { log "hello"; }
+ none::<int>. { log "hello"; }
}
}
-fn main() { foo(); }
\ No newline at end of file
+fn main() { foo(); }
fn nested(o: t) {
alt o {
- bar(i, some[int](_)) { log_err "wrong pattern matched"; fail; }
+ bar(i, some::<int>(_)) { log_err "wrong pattern matched"; fail; }
_ { log_err "succeeded"; }
}
}
-fn main() { nested(bar(1, none[int])); }
+fn main() { nested(bar(1, none::<int>)); }
t.take(3);
}
- let p = mk_port[int]();
+ let p = mk_port::<int>();
let t1: taker = adder(@mutable 0);
let t2: taker = sender(p.mk_chan());
// -*- 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() { }
fn f<T>() -> option<T> { ret none; }
-fn main() { f[int](); }
+fn main() { f::<int>(); }
// power of two so needs to be rounded up. Don't trigger any
// assertions.
fn test_init() {
- let myport = mk_port[record]();
+ let myport = mk_port::<record>();
let mychan = myport.mk_chan();
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
send(mychan, val);
// Don't allow the buffer to shrink below it's original size
fn test_shrink1() {
- let myport = comm::mk_port[i8]();
+ let myport = comm::mk_port::<i8>();
let mychan = myport.mk_chan();
send(mychan, 0i8);
let x = myport.recv();
}
fn test_shrink2() {
- let myport = mk_port[record]();
+ let myport = mk_port::<record>();
let mychan = myport.mk_chan();
for each i: uint in uint::range(0u, 100u) {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
// Test rotating the buffer when the unit size is not a power of two
fn test_rotate() {
- let myport = mk_port[record]();
+ let myport = mk_port::<record>();
let mychan = myport.mk_chan();
for each i: uint in uint::range(0u, 100u) {
let val = {val1: i as u32, val2: i as u32, val3: i as u32};
// Test rotating and growing the buffer when
// the unit size is not a power of two
fn test_rotate_grow() {
- let myport = mk_port[record]();
+ let myport = mk_port::<record>();
let mychan = myport.mk_chan();
for each j: uint in uint::range(0u, 10u) {
for each i: uint in uint::range(0u, 10u) {
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>>]();
+ let ctrl = mk_port::<_chan<command<K, V>>>();
send(c, ctrl.mk_chan());
}
fn main() { }
let b: [int] = ~[];
- alt none[int] {
- some[int](_) { for i: int in c { log a; let a = 17; b += ~[a]; } }
+ alt none::<int> {
+ some::<int>(_) { for i: int in c { log a; let a = 17; b += ~[a]; } }
_ {}
}
}
tag opt<T> { none; }
-fn main() { let x = none[int]; alt x { none[int]. { log "hello world"; } } }
+fn main() {
+ let x = none::<int>; alt x { none::<int>. { log "hello world"; } }
+}
tag clam<T> { a(T); }
-fn main() { let c = a(2); alt c { a[int](_) { } } }
+fn main() { let c = a(2); alt c { a::<int>(_) { } } }
fn uhoh<T>(v: &[clam<T>]) {
alt v.(1) {
- a[T](t, u) { log "incorrect"; log u; fail; }
- b[T]. { log "correct"; }
+ 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)];
- uhoh[int](v);
+ let v: [clam<int>] = ~[b::<int>, b::<int>, a::<int>(42, 17)];
+ uhoh::<int>(v);
}
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"));
}
assert(#ident_to_str[use_mention_distinction]
== "use_mention_distinction");
-}
\ No newline at end of file
+}
fn meth(x: &T) { }
}
-fn main() { foo[colour]().meth(red); }
+fn main() { foo::<colour>().meth(red); }
}
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::comm;
fn start(c: comm::_chan<str>) {
- let p = comm::mk_port<str>();
+ let p = comm::mk_port::<str>();
c.send(p.mk_chan().unsafe_ptr());
let a;
}
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();
}
}
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
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);
message.
*/
fn main() {
- let po = mk_port[int]();
+ let po = mk_port::<int>();
let ch = po.mk_chan();
send(ch, 42);
let r = po.recv();
use std;
fn main() {
- assert (size_of[u8]() == 1 as uint);
- assert (size_of[u32]() == 4 as uint);
- assert (size_of[char]() == 4 as uint);
- assert (size_of[i8]() == 1 as uint);
- assert (size_of[i32]() == 4 as uint);
- assert (size_of[{a: u8, b: i8}]() == 2 as uint);
- assert (size_of[{a: u8, b: i8, c: u8}]() == 3 as uint);
+ assert (size_of::<u8>() == 1 as uint);
+ assert (size_of::<u32>() == 4 as uint);
+ assert (size_of::<char>() == 4 as uint);
+ assert (size_of::<i8>() == 1 as uint);
+ assert (size_of::<i32>() == 4 as uint);
+ assert (size_of::<{a: u8, b: i8}>() == 2 as uint);
+ assert (size_of::<{a: u8, b: i8, c: u8}>() == 3 as uint);
// Alignment causes padding before the char and the u32.
- assert (size_of[{a: u8, b: i8, c: {u: char, v: u8}, d: u32}]() ==
+ assert (size_of::<{a: u8, b: i8, c: {u: char, v: u8}, d: u32}>() ==
16 as uint);
- assert (size_of[int]() == size_of[uint]());
- assert (size_of[{a: int, b: ()}]() == size_of[int]());
- assert (size_of[{a: int, b: (), c: ()}]() == size_of[int]());
- assert (size_of[int]() == size_of[{x: int}]());
-}
\ No newline at end of file
+ assert (size_of::<int>() == size_of::<uint>());
+ assert (size_of::<{a: int, b: ()}>() == size_of::<int>());
+ assert (size_of::<{a: int, b: (), c: ()}>() == size_of::<int>());
+ assert (size_of::<int>() == size_of::<{x: int}>());
+}
fn null<T>() -> *T { unsafe::reinterpret_cast(0) }
fn main() {
- null[int]();
+ null::<int>();
}
fn foo<T>(o: &myoption<T>) -> int {
let x: int = 5;
- alt o { none[T]. { } some[T](t) { x += 1; } }
+ alt o { none::<T>. { } some::<T>(t) { x += 1; } }
ret x;
}
fn foo<T>(o: &myoption<T>) -> int {
let x: int;
- alt o { none[T]. { fail; } some[T](t) { x = 5; } }
+ alt o { none::<T>. { fail; } some::<T>(t) { x = 5; } }
ret x;
}
log s;
s += "there";
log s;
- auto z = std::vec.alloc[int](10 as uint);
+ auto z = std::vec.alloc::<int>(10 as uint);
}
assert (str::byte_len(s) == 10u);
assert (str::char_len(s) == 4u);
- assert (vec::len[char](str::to_chars(s)) == 4u);
+ assert (vec::len::<char>(str::to_chars(s)) == 4u);
assert (str::eq(str::from_chars(str::to_chars(s)), s));
assert (str::char_at(s, 0u) == 'e');
assert (str::char_at(s, 1u) == 'é');
assert (str::refcount(s) == const_refcount);
assert (str::refcount(mumble) == const_refcount);
log v.(0);
- log vec::len[str](v);
+ log vec::len::<str>(v);
assert (str::eq(v.(0), mumble));
- assert (vec::len[str](v) == 1u);
+ assert (vec::len::<str>(v) == 1u);
} // ref down: mumble, s,
log str::refcount(s);
let act;
let exp;
act = bitv::create(0u, false);
- exp = vec::init_elt[uint](0u, 0u);
- // FIXME: why can't I write vec[uint]()?
+ exp = vec::init_elt::<uint>(0u, 0u);
+ // FIXME: why can't I write vec::<uint>()?
assert (bitv::eq_ivec(act, exp));
}
fn test() {
let x = @3;
let y = @3;
- assert (box::ptr_eq[int](x, x));
- assert (box::ptr_eq[int](y, y));
- assert (!box::ptr_eq[int](x, y));
- assert (!box::ptr_eq[int](y, x));
-}
\ No newline at end of file
+ assert (box::ptr_eq::<int>(x, x));
+ assert (box::ptr_eq::<int>(y, y));
+ assert (!box::ptr_eq::<int>(x, y));
+ assert (!box::ptr_eq::<int>(y, x));
+}
#[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]();
+ 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 {
alt a {
- onepar[T](a1) {
- alt b { onepar[T](b1) { ret a1 == b1; } _ { ret false; } }
+ onepar::<T>(a1) {
+ alt b { onepar::<T>(b1) { ret a1 == b1; } _ { ret false; } }
}
- twopar[T](a1, a2) {
+ twopar::<T>(a1, a2) {
alt b {
- twopar[T](b1, b2) { ret a1 == b1 && a2 == b2; }
+ twopar::<T>(b1, b2) { ret a1 == b1 && a2 == b2; }
_ { ret false; }
}
}
- threepar[T](a1, a2, a3) {
+ threepar::<T>(a1, a2, a3) {
alt b {
- threepar[T](b1, b2, b3) {
+ threepar::<T>(b1, b2, b3) {
ret a1 == b1 && a2 == b2 && a3 == b3;
}
_ { ret false; }
log "*** end test boxes";
log "test parameterized: int";
let eq1: eqfn<int> = inteq;
- test_parameterized[int](eq1, 5, 72, 64, 175);
+ test_parameterized::<int>(eq1, 5, 72, 64, 175);
log "*** test parameterized: @int";
let eq2: eqfn<@int> = intboxeq;
- test_parameterized[@int](eq2, @5, @72, @64, @175);
+ test_parameterized::<@int>(eq2, @5, @72, @64, @175);
log "*** end test parameterized @int";
log "test parameterized: taggy";
let eq3: eqfn<taggy> = taggyeq;
- test_parameterized[taggy](eq3, one(1), two(1, 2), three(1, 2, 3),
+ 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,
- onepar[int](1),
- twopar[int](1, 2),
- threepar[int](1, 2, 3),
- twopar[int](17, 42));
- log "*** end 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),
+ twopar::<int>(17, 42));
+ log "*** end test parameterized: taggypar::<int>";
log "*** test parameterized: reccy";
let reccy1: reccy = {x: 1, y: 2, t: one(1)};
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;
- test_parameterized[reccy](eq5, reccy1, reccy2, reccy3, reccy4);
+ test_parameterized::<reccy>(eq5, reccy1, reccy2, reccy3, reccy4);
log "*** end test parameterized: reccy";
log "*** done";
}
fn test_find_success() {
let l = from_vec(~[0, 1, 2]);
fn match(i: &int) -> option::t<int> {
- ret if i == 2 { option::some(i) } else { option::none[int] };
+ ret if i == 2 { option::some(i) } else { option::none::<int> };
}
let rs = list::find(l, match);
assert (rs == option::some(2));
#[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]);
+ assert (rs == option::none::<int>);
}
#[test]
fn test_has() {
let l = from_vec(~[5, 8, 6]);
- let empty = list::nil[int];
+ let empty = list::nil::<int>;
assert (list::has(l, 5));
assert (!list::has(l, 7));
assert (list::has(l, 8));
let eqer_str: map::eqfn<str> = str::eq;
log "uint -> uint";
let hm_uu: map::hashmap<uint, uint> =
- map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
+ map::mk_hashmap::<uint, uint>(hasher_uint, eqer_uint);
assert (hm_uu.insert(10u, 12u));
assert (hm_uu.insert(11u, 13u));
assert (hm_uu.insert(12u, 14u));
let twelve: str = "twelve";
log "str -> uint";
let hm_su: map::hashmap<str, uint> =
- map::mk_hashmap[str, uint](hasher_str, eqer_str);
+ 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", 14u));
assert (hm_su.get("twelve") == 12u);
log "uint -> str";
let hm_us: map::hashmap<uint, str> =
- map::mk_hashmap[uint, str](hasher_uint, eqer_uint);
+ 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, "fourteen"));
assert (str::eq(hm_us.get(12u), "twelve"));
log "str -> str";
let hm_ss: map::hashmap<str, str> =
- map::mk_hashmap[str, str](hasher_str, eqer_str);
+ map::mk_hashmap::<str, str>(hasher_str, eqer_str);
assert (hm_ss.insert(ten, "twelve"));
assert (hm_ss.insert(eleven, "thirteen"));
assert (hm_ss.insert(twelve, "fourteen"));
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);
+ map::mk_hashmap::<uint, uint>(hasher_uint, eqer_uint);
let i: uint = 0u;
while i < num_to_insert {
assert (hm_uu.insert(i, i * i));
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);
+ map::mk_hashmap::<str, str>(hasher_str, eqer_str);
i = 0u;
while i < num_to_insert {
assert (hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u)));
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);
+ map::mk_hashmap::<uint, uint>(hasher, eqer);
let i: uint = 0u;
while i < num_to_insert {
assert (hm.insert(i, i * i));
let v: util.option<uint> = hm.remove(i);
alt (v) {
- case (util.some[uint](u)) {
+ case (util.some::<uint>(u)) {
assert (u == (i * i));
}
- case (util.none[uint]()) { fail; }
+ case (util.none::<uint>()) { fail; }
}
* but we util.option is a tag type so util.some and util.none are
#[test]
fn test_contains_key() {
let key = "k";
- let map = map::mk_hashmap[str, str](str::hash, str::eq);
+ let map = map::mk_hashmap::<str, str>(str::hash, str::eq);
assert (!map.contains_key(key));
map.insert(key, "val");
assert (map.contains_key(key));
#[test]
fn test_find() {
let key = "k";
- let map = map::mk_hashmap[str, str](str::hash, str::eq);
+ let map = map::mk_hashmap::<str, str>(str::hash, str::eq);
assert (std::option::is_none(map.find(key)));
map.insert(key, "val");
assert (std::option::get(map.find(key)) == "val");
use std;
#[test]
-fn test() { let x = std::option::some[int](10); }
\ No newline at end of file
+fn test() { let x = std::option::some::<int>(10); }
import std::int;
fn check_sort(v1: &[mutable int], v2: &[mutable int]) {
- let len = std::vec::len[int](v1);
+ let len = std::vec::len::<int>(v1);
fn ltequal(a: &int, b: &int) -> bool { ret a <= b; }
let f = ltequal;
- std::sort::quick_sort[int](f, v1);
+ std::sort::quick_sort::<int>(f, v1);
let i = 0u;
while i < len { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
}
use std;
fn check_sort(v1: &[mutable int], v2: &[mutable int]) {
- let len = std::vec::len[int](v1);
+ let len = std::vec::len::<int>(v1);
fn lt(a: &int, b: &int) -> bool { ret a < b; }
fn equal(a: &int, b: &int) -> bool { ret a == b; }
let f1 = lt;
let f2 = equal;
- std::sort::quick_sort3[int](f1, f2, v1);
+ std::sort::quick_sort3::<int>(f1, f2, v1);
let i = 0u;
while i < len { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
}
0x10u8, 0x0du8, 0xb4u8, 0xb3u8]}];
let tests = fips_180_1_tests + wikipedia_tests;
fn check_vec_eq(v0: &[u8], v1: &[u8]) {
- assert (vec::len[u8](v0) == vec::len[u8](v1));
- let len = vec::len[u8](v0);
+ assert (vec::len::<u8>(v0) == vec::len::<u8>(v1));
+ let len = vec::len::<u8>(v0);
let i = 0u;
while i < len {
let a = v0.(i);
use std;
fn check_sort(v1: &[int], v2: &[int]) {
- let len = std::vec::len[int](v1);
+ let len = std::vec::len::<int>(v1);
fn lteq(a: &int, b: &int) -> bool { ret a <= b; }
let f = lteq;
- let v3 = std::sort::merge_sort[int](f, v1);
+ let v3 = std::sort::merge_sort::<int>(f, v1);
let i = 0u;
while i < len { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
}
#[test]
fn test_is_empty() {
- assert (vec::is_empty[int](~[]));
+ assert (vec::is_empty::<int>(~[]));
assert (!vec::is_empty(~[0]));
}
#[test]
fn test_is_not_empty() {
assert (vec::is_not_empty(~[0]));
- assert (!vec::is_not_empty[int](~[]));
+ assert (!vec::is_not_empty::<int>(~[]));
}
#[test]
let f = times;
let v0 = ~[1, 2, 3, 4, 5];
let v1 = ~[5, 4, 3, 2, 1];
- let u = vec::map2[int, int, int](f, v0, v1);
+ let u = vec::map2::<int, int, int>(f, v0, v1);
let i = 0;
while i < 5 { assert (v0.(i) * v1.(i) == u.(i)); i += 1; }
}
fn halve(i: &int) -> option::t<int> {
if i % 2 == 0 {
- ret option::some[int](i / 2);
- } else { ret option::none[int]; }
+ ret option::some::<int>(i / 2);
+ } else { ret option::none::<int>; }
}
fn halve_for_sure(i: &int) -> int { ret i / 2; }
let all_even: [int] = ~[0, 2, 8, 6];
#[test]
fn test_position() {
let v1: [int] = ~[1, 2, 3, 3, 2, 5];
- assert (position(1, v1) == option::some[uint](0u));
- assert (position(2, v1) == option::some[uint](1u));
- assert (position(5, v1) == option::some[uint](5u));
- assert (position(4, v1) == option::none[uint]);
+ assert (position(1, v1) == option::some::<uint>(0u));
+ assert (position(2, v1) == option::some::<uint>(1u));
+ assert (position(5, v1) == option::some::<uint>(5u));
+ assert (position(4, v1) == option::none::<uint>);
}
#[test]
fn less_than_three(i: &int) -> bool { ret i < 3; }
fn is_eighteen(i: &int) -> bool { ret i == 18; }
let v1: [int] = ~[5, 4, 3, 2, 1];
- assert (position_pred(less_than_three, v1) == option::some[uint](3u));
- assert (position_pred(is_eighteen, v1) == option::none[uint]);
+ assert (position_pred(less_than_three, v1) == option::some::<uint>(3u));
+ assert (position_pred(is_eighteen, v1) == option::none::<uint>);
}
#[test]
vec::reverse(v);
assert (v.(0) == 20);
assert (v.(1) == 10);
- let v2 = vec::reversed[int](~[10, 20]);
+ let v2 = vec::reversed::<int>(~[10, 20]);
assert (v2.(0) == 20);
assert (v2.(1) == 10);
v.(0) = 30;
assert (v2.(0) == 20);
// Make sure they work with 0-length vectors too.
- let v4 = vec::reversed[int](~[]);
+ let v4 = vec::reversed::<int>(~[]);
let v3: [mutable int] = ~[mutable];
- vec::reverse[int](v3);
+ vec::reverse::<int>(v3);
}
// Local Variables:
let s2: str = str::unsafe_from_bytes(v);
let i: uint = 0u;
let n1: uint = str::byte_len(s1);
- let n2: uint = vec::len[u8](v);
+ let n2: uint = vec::len::<u8>(v);
assert (n1 == n2);
while i < n1 {
let a: u8 = s1.(i);