Skip to content

Instantly share code, notes, and snippets.

@benw
Created May 28, 2013 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benw/5660118 to your computer and use it in GitHub Desktop.
Save benw/5660118 to your computer and use it in GitHub Desktop.
In which I learn to use the ref keyword.
enum List {
Nil,
Node(int, ~List)
}
fn walk(l: &List) -> ~str {
match *l {
Node(i, ref rest) => fmt!("%d %s", i, walk(*rest)),
Nil => ~"end"
}
}
fn main() {
let list = Node(5, ~Node(4, ~Node(3, ~Node(2, ~Nil))));
println(walk(&list));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment