This file contains 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 add<T: Add<T, T>>( | |
a: proc() -> T, | |
b: proc() -> T | |
) -> proc() -> T { | |
proc() a() + b() | |
} | |
fn main() { | |
let a = proc() 2; | |
let b = proc() 3; |
This file contains 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
/// Expr wraps a 'proc' that computes a value and a new expression state. | |
pub struct Expr<T, Env> { | |
/// Runs the expression and computes the new expression state. | |
run: proc(&mut Env) -> (T, Expr<T, Env>) | |
} | |
pub fn run<Env, V>(env: &mut Env, expr: &mut Expr<V, Env>) -> V { | |
let (v, n) = (expr.run)(env); | |
expr.run = n.run; | |
v |
This file contains 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
#[feature(macro_rules)] | |
extern mod expr; | |
macro_rules! run( | |
($expr:expr $env:expr) => { | |
let (v, n) = (expr.run)(&mut env); | |
expr = n; | |
v | |
} |
This file contains 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 TodoList { | |
} | |
pub fn todo(task: TodoList) -> bool { | |
match task { | |
} | |
} |
This file contains 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
/// Executes a list of expressions. | |
pub fn exec<Env>(mut a: ~[Expr<(), Env>]) -> Expr<(), Env> { | |
Expr { | |
run: proc(env: &mut Env) { | |
for i in range(0, a.len()) { | |
let (_, exn) = (a[i].run)(env); | |
a[i] = exn; | |
} | |
((), exec(a)) | |
} |
This file contains 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
error: wrong number of type arguments: expected 1 but found 2 | |
/home/sven/Desktop/cgmath-rs/src/cgmath/dual.rs:38 impl<S: Primitive> Vector<S, [S, ..2]> for Dual<S> {} | |
^~~~~~~~~~~~~~~~~~~ |
This file contains 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
pub struct Player { | |
name: ~str | |
} | |
pub struct Enemy { | |
name: ~str | |
} | |
pub trait Entity { |
This file contains 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
/* | |
Tests the Any trait. | |
*/ | |
pub struct Player { | |
name: ~str | |
} |
This file contains 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
#[inline] | |
fn as_ref<'a, T: 'static>(a: &'a Entity) -> Option<&'a T> { | |
if TypeId::of::<T>() == TypeId::of::<&'static Entity>() { | |
Some(unsafe { transmute(a.as_void_ptr()) }) | |
} else { | |
None | |
} | |
} |
This file contains 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 type_name<T>(_: &T) -> &'static str { | |
unsafe { (*::std::unstable::intrinsics::get_tydesc::<T>()).name } | |
} | |
// USAGE | |
println!("{}", type_name(&x)); |
OlderNewer