Created
June 2, 2010 14:36
-
-
Save nddrylliog/422440 to your computer and use it in GitHub Desktop.
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
Node: class { | |
data: String | |
children: Node[] | |
init: func ~withString (=data) {} | |
init: func ~withStringAndChildren (=data, =children) {} | |
walk: func (f: Func (String, Int)) { | |
_walk(f, 0) | |
} | |
_walk: func (f: Func (String, Int), depth: Int) { | |
f(data, depth) | |
for(i in 0..children length) { | |
children[i] _walk(f, depth + 1) | |
} | |
} | |
} | |
node: func ~withString (s: String) -> Node { | |
Node new(s) | |
} | |
node: func ~withStringAndChildren (s: String, children: Node[]) -> Node { | |
Node new(s, children) | |
} | |
node := node("", [ | |
node("1. Why arrays are good for you.") | |
node("2. Why commas aren't the only separators") | |
node("3. Why C arrays aren't enough", [ | |
node("a. Where's mah length?") | |
node("b. Segfault party", [ | |
node("i. Bound checking for the programmer") | |
node("ii. Bound checking for the machine") | |
]) | |
]) | |
node("4. multi-dimensional ftw!") | |
]) | |
node walk(|s, depth| | |
(" " * depth + s) println() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment