4 ms·
It was effectively a parsing problem. When building a tree recursively, it's natural to return the finished subtree, but more information was needed to keep tra
by skybrian 6y ago
It was effectively a parsing problem. When building a tree recursively, it's natural to return the finished subtree, but more information was needed to keep track of what gets parsed next. You would need to return both the result and the start of the unparsed input.
In imperative languages, parsers are often written using the fields of an object or struct to hold the parser state. But if you're just writing a single function then it becomes more natural to keep the parser state in local variables, and recursion means you don't have easy access to it.
- Jtsummers 6y agoThat makes sense, thanks.