Skip to content

Instantly share code, notes, and snippets.

@nddrylliog
Created June 2, 2010 14:36
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 nddrylliog/422440 to your computer and use it in GitHub Desktop.
Save nddrylliog/422440 to your computer and use it in GitHub Desktop.
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