2 ms·
Well, obviously the - is a base case and should be removed from successive recursions. And I don't think it is difficult to reason about resource usage. Tail-c
by duaneb 11y ago
Well, obviously the - is a base case and should be removed from successive recursions.
And I don't think it is difficult to reason about resource usage. Tail-calls are very intuitive. Some languages (e.g. scala) allow you to force a call to be a tail call (or fail with an error).
I suspect that preferring explicit over implicit is why coding standards forbid recursion. However, many algorithms become straight-up awkward when having to manipulate the "call stack" manually: see traversal of graphs.
Finally, what you were really complaining about was the fact that he didn't handle multiple dashes. It has very little to do with recursion, which is just a different way to fold the same semantics you'd still have wrong with an iterative version. It would never overflow the stack because why would you accept unlimited minuses? You're not evaluating an expression, you're parsing a known format and can fail fast.