3 ms·
Re: TCO Does the language give any guarantee that TCO was applied? In other words can it give you an error that the recursion is not of tail call form? Because
by xonix 11mo ago
Re: TCO
Does the language give any guarantee that TCO was applied? In other words can it give you an error that the recursion is not of tail call form? Because I imagine a probability of writing a recursion and relying on it being TCO-optimized, where it's not. I would prefer if a language had some form of explicit TCO modifier for a function. Is there any language that has this?
- stellartux 11mo agoSounds a bit like Clojure's "recur". https://clojuredocs.org/clojure.core/recur https://clojuredocs.org/clojure.core/recur
- ZiiS 11mo agoAt least in Lua then the rule is simply 'last thing a function dose' this is unambiguous. `return f()` is always a tail call and `return f() + 1` never is.
- deleted 11mo ago[deleted]
- normie3000 11mo agoWhat about: return 1 + f() ?
- ZiiS 11mo agoNo, the last thing is the +; which can't run till it knows both values. (Reverse Polish notation is clearer, but humans prefer infix operators for some reason)
- draven 11mo agoScala has the @tailrec annotation which will raise a warning if the function can’t be TCO’d
- alexisread 11mo agoAlthough it’s a bit weird, Able Forth has the explicit word ~ https://github.com/ablevm/able-forth/blob/current/forth.scr https://github.com/ablevm/able-forth/blob/current/forth.scr I do prefer this as it keeps the language more regular (fewer surprises)
- garaetjjte 11mo agoC, with [[clang::musttail]]