I wrote some stuff about and tail call optimization that mentions and

Not a really deep post but sometimes is cool to remind these topics.

It's kind of a draft still, but I think it's fine.

@ekaitz_zarraga I don't understand anything, but I do love your titles: «Sociedad Bilbaína», «Call me maybe»... You are an artist :)

@editora If you know some PHP you should be able to understand the very basics of what I say... That probably is a problem of my explanation...

Thank you, titles are just magic. They *happen*. I don't really choose them, they appear.

@ekaitz_zarraga well, in your post It isn't all Greek to me, only it's Basque :D

Great explanation, in particular the bit where you show the propagation of the return value.

The one thing I was missing was the distinction between the general tail call and the special case of tail recursion, which is relevant because as you mentioned, some languages only optimize tail recursion.

The description that it's almost like a goto works for tail recursion, but for general tail call optimization what happens is that you throw away your own stack frame, almost-returning from your function, before you call the intended function. The called function replaces your function's place on the stack, just like how a process can replace another when you call execve, e.g. when you call exec in bash.

@clacke Yeah, I didn't want to make it too long... but yeah: Lua supports Proper Tail Calls, which is more than tai recursion optimization.

It's not the same thing, as you said. Yeah.

And the exec example you mention is the reason why python doesn't support it. :)

So, I agree with you but I want to leave some stuff for the reader. I like to have many links for people to investigate.


Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!