5 ms·
I wish that Rust would follow the lead of some languages in allowing one to explicitly mark a function as recursive. (Not exactly the same as TCO, I understand,
by ragnese 6y ago
I wish that Rust would follow the lead of some languages in allowing one to explicitly mark a function as recursive. (Not exactly the same as TCO, I understand, but related)
I understand the argument against doing TCO in a low level language like Rust (debugging stack traces, etc). But as an opt-in? Yes, please!
OCaml, which is like Rust's muse/parent, does it. Kotlin and Clojure do that as well, IIRC.
- eru 6y agoFrom my point of view TCO is exactly most useful when you are dealing with mutually recursive functions. Like eg a state machine where one state = one function. That's also the example in the corresponding Lambda the Ultimate paper. But yes, getting TCO for simple self-recursive function is better than nothing.
- tomp 6y agoTCO is exactly as useful as async/await. Could you write an equivalent state machine manually? Yes. Do you want to? No.
- eru 6y agoWhat do you mean by 'exactly as useful'? I can see how they are both useful, and there are even some problems were either approach works. But I don't see an exact correspondence?
- say_it_as_it_is 6y agoSince you understand the argument against TCO in Rust, would you mind explaining it to those who don't?
- astrange 6y agoThe function that performs the tail-call won't show up in stack traces. This is intentional (and needed) when it's done to eliminate an infinite number of recursive calls, but if it's just a utility function then it can be confusing. As an ObjC example, there's an objc_msgSend call between every two methods in a stack trace, but you never see it. In practice this has never been a problem for me.