why isn't inline on tailrec functions supported? I...
# announcements
t
why isn't inline on tailrec functions supported? It seems like a kinda obvious thing to add, as if you want to be more FP you'd use more tailrec fun's than while() loops.
n
I realize it's a bit of a non-answer but for me the more surprising part is that kotlin supports tailrec to start with
clojure doesn't even support tail recursion. It's just not a terribly useful feature unless your language wants to do everything to avoid loops for some reason (like scheme for educational/simplicity reasons), or if your language is so heavy on purity that you don't want to mutate the local variable for a loop
t
tailrec = while loop to the compiler... which is already inlined.
@Nir it's in scala... so there is JVM code to steal 🙂
@Ruckus So you think while() loops arn't inlined? Every while() loop is a function call?
a tailrec function and a while() loop are equivalent, by definition.
what am I missing? inline = skip the call, copy'n paste this code into everyplace that calls it.
r
I shall delete my comments to hide my shame from the world.
t
@Nir I prefer tailrec to while() except for the trivial case. no `var`s easier for the compiler to figure out there are no side effects. should result if faster code (but I've never actually tested). maybe just a story I tell myself.
@Ruckus no worries 🙂 I get confused between unrolls and inline sometimes.
👍 1
n
Seems unlikely it results in faster code, but I don't know the JVM well
j
@Nir Clojure had support for tail recursion 3 years ago, there's just no explicit key word for it. Same usage patterns apply - has to be the last statement etc...
1
It also has trampoline as part of the standard library
n
it looks like they just haven't gotten around to it yet https://youtrack.jetbrains.com/issue/KT-27897
t
@Jakub Pi I've never heard of trampoline before this. that's a neat idea. thanks!
@nanodeath a 4 year old ticket w/ not planned implementation doesn't sound too hopeful for "getting around to it". But at least they are aware of it, which is better than nothing.
n
at least it's not closed 😛