Remix.run Logo
xonix 7 hours 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?

ZiiS 7 hours ago | parent | next [-]

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

3 hours ago | parent [-]
[deleted]
alexisread 6 hours ago | parent | prev | next [-]

Although it’s a bit weird, Able Forth has the explicit word ~

https://github.com/ablevm/able-forth/blob/current/forth.scr

I do prefer this as it keeps the language more regular (fewer surprises)

stellartux 7 hours ago | parent | prev | next [-]

Sounds a bit like Clojure's "recur". https://clojuredocs.org/clojure.core/recur

garaetjjte 2 hours ago | parent | prev | next [-]

C, with [[clang::musttail]]

draven 7 hours ago | parent | prev [-]

Scala has the @tailrec annotation which will raise a warning if the function can’t be TCO’d