Created
May 28, 2013 02:12
-
-
Save benw/5660118 to your computer and use it in GitHub Desktop.
In which I learn to use the ref keyword.
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 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