Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



From 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.


TCO is exactly as useful as async/await. Could you write an equivalent state machine manually? Yes. Do you want to? No.


What 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?


Since you understand the argument against TCO in Rust, would you mind explaining it to those who don't?


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: