3 ms·
> Is your code less functional and more imperative style due to Rust? I would imagine so. Rust doesn't support tail call optimization, and variables are immuta
by stuartd 6y ago
> Is your code less functional and more imperative style due to Rust?
I would imagine so. Rust doesn't support tail call optimization, and variables are immutable only by default.
- zozbot234 6y agoLLVM should optimize tailcalls and sibcalls. But tail call optimization has unexpected interactions with the extended RAII that Rust uses because stuff has to be dropped at the end of its lifetime, so the code that's running in "tail" position is sometimes not what you expect.
- thaneross 6y agoAs a beginner to Rust I'm surprised by this. Given the Rust compiler is able to figure out the lifetimes in the recursive case, you'd think the lifetimes within the tail-optimized loop would be same. Doesn't the lexical scoping of the loop's body have the equivalent lifecycle of a recursive call (drop at the end of the loop vs the end of the function)?