4 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 9mo 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 9mo agoSounds a bit like Clojure's "recur". https://clojuredocs.org/clojure.core/recur https://clojuredocs.org/clojure.core/recur
- ZiiS 9mo 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 9mo ago[deleted]
- normie3000 9mo agoWhat about: return 1 + f() ?
- ZiiS 9mo 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 9mo agoScala has the @tailrec annotation which will raise a warning if the function can’t be TCO’d
- alexisread 9mo 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 9mo agoC, with [[clang::musttail]]