3 ms·
Bottom up tree traversal doesn't require an explicit for loop as long as the language supports first class functions. bottomsUp(node) { recurseChildr
by pacala 14y ago
Bottom up tree traversal doesn't require an explicit for loop as long as the language supports first class functions.
bottomsUp(node) {
recurseChildren(node, &bottomsUp);
switch (node.id) {
case FOO:
break;
case BAR:
break;
}
}
At the end of the day the actual code (the switch) is what matters, and the "glue" can be made a couple of lines either way.
PS. On a separate language feature, I like match with algebraic datatypes more than switch, but I don't know if Go has match. Go Rust!