▲ | pdpi 5 days ago | |||||||||||||||||||||||||
> Tail recursion IME is a bigger foot gun This is true for some languages, but not all. E.g. scala has @tailrec annotations, which make it a compile error for the annotated function to not be tail recursive. Clojure doesn't have tail call elimination, but has the `recur` special form for explicit recursion that is guaranteed to not consume any stack space.Rust has reserved the `become` keyword that will eventually guarantee tail call elimination (So pretty similar to Clojure's recur, but I think Rust's version will allow mutual recursion) Zig goes the whole hog, and has `@call(modifier, fn, args)`, where `modifier` can be things like compile_time, always_tail, always_inline, never_tail, never_inline, and a bunch other desirable guarantees you might want. | ||||||||||||||||||||||||||
▲ | aw1621107 5 days ago | parent | next [-] | |||||||||||||||||||||||||
> Rust has reserved the `become` keyword that will eventually guarantee tail call elimination (So pretty similar to Clojure's recur, but I think Rust's version will allow mutual recursion) Support got added to nightly quite recently, in fact - on 2025-07-31 [0]. | ||||||||||||||||||||||||||
▲ | LandR 4 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Clojure has mutual recursion via (trampoline ...) | ||||||||||||||||||||||||||
▲ | phh 4 days ago | parent | prev [-] | |||||||||||||||||||||||||
> > Tail recursion IME is a bigger foot gun > This is true for some languages, but not all. Useless anecdote that tail-recursive can be a foot gun even in Scala. I did a (screening) job interview at Datadog, they asked for "give the spare change back on that amount of money" exercise (simple variant), "in whichever language you want". I did my implementation in tail-recursive Scala (with the annotation). I ended up trying to explain that tail-recursivity doesn't explode in memory for the rest of the call (and failed) | ||||||||||||||||||||||||||
|