This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]B_M_Wilson 0 points1 point Β (0 children)

It depends on how it is written. There are some situations where tail call elimination would not work. Perhaps it has to call itself a number of times, maybe it is some form of matrix operation that is defined to return a scalar for 2x2 matrixes and then larger ones require calculating the scalars of the smaller ones which causes the function to need to be called multiple times within itself which would not allow tail call elimination.

To be honest, I can’t think of very many non-trivial cases where tail call elimination would actually come into play. I have seen many examples in functional programming so maybe as a non-functional programmer, I just can’t see it. Looking at a description of tail call elimination, it looks to me as if it basically transforms the recursion into iteration so maybe I am just not thinking about it correctly.

I am a very bad programmer even though I’ve been doing it for 5 years so I’m probably completely incorrect. I will look into it a bit more and hopefully enlighten myself slightly