This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn tail<A,IA:iterable<A>>( | |
iter: IA, op: fn(A)) { | |
let first = true; | |
iter.iter {|e| | |
if !first { | |
op(e); | |
} | |
first = false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn foo() -> @memory_pool { | |
// let the region for this block be "r_foo" | |
let p: @memory_pool = pool(); | |
let x: &r_foo.T = new(p) T; | |
ret p; // x cannot be returned because r_foo is not in scope | |
} | |
fn bar() { | |
let p = foo(); // memory for p is not yet freed... | |
// ...but I can't access the prior contents. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[non_copyable] | |
enum one_shot<A,T> = fn~(A) -> T; | |
fn execute(-f: one_shot<A>, a: A) -> T { (*f)(a) } | |
fn mk_one_shot_adder(-v1: ~int) -> one_shot<int,int> { | |
let v1 = ~some(move v1); // this "move" is not yet legal syntax | |
ret one_shot(fn~[move v1](v2: int) -> int { | |
let x = none; | |
x <-> v1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iface i { fn foo() -> self<>; } | |
fn foo<T:i>(v: T) -> T { | |
ret v.foo(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iface i { fn foo() -> self<>; } | |
fn foo<T:i>(v: T) -> T { | |
ret v.foo(); | |
} | |
impl of i for uint { | |
fn foo() -> uint { ret self; } | |
} | |
fn main() { | |
let x: i = 3u as i; | |
let y = foo(x); // y has type i, but is in fact a uint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum t { | |
ty_nil, | |
} | |
fn mk_nil<C:ty_ops>(cx: C) -> t { | |
cx.mk() | |
} | |
iface ty_ops { | |
fn mk() -> t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn concat<T: copy>(v: [const [const T]]) -> [T] { | |
let mut r: [T] = []; | |
for inner: [T] in v { r += inner; } | |
ret r; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn with<T,R>(v: T, f: f(T) -> R) -> R { | |
f(v) | |
} | |
fn some_func(a: uint, b: uint) -> uint { | |
with( | |
fn&(x: uint) -> uint { a + b + x } | |
) {|helper| | |
helper(22) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl y for option<int> { | |
fn hi() { io::print("int"); } | |
} | |
impl x for option<uint> { | |
fn hi() { io::print("uint"); } | |
} | |
fn to_uint(x: option<uint>) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn normalize_ty(cx: ctxt, t0: t) -> t { | |
fold_sty_to_ty(get(t0).struct) { |t| | |
normalize_ty(cx, t) | |
} | |
} |