Skip to content

Instantly share code, notes, and snippets.

@jasom
Created July 13, 2013 00:38
Show Gist options
  • Select an option

  • Save jasom/5988857 to your computer and use it in GitHub Desktop.

Select an option

Save jasom/5988857 to your computer and use it in GitHub Desktop.
use std::io;
enum List {
Cons(uint,~List),
Nil()
}
fn cons(x : uint, l : ~List) -> ~List{
return ~Cons(x,l);
}
fn printl(mut l : &~List) {
io::print("(");
loop {
match l {
&~Cons(x, ref next) => {
l = next;
io::print(fmt!("%u ",x))
}
&~Nil() => break
}
}
io::print(")");
}
fn main() {
printl(&cons(1,cons(2,cons(3,~Nil))));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment