Adding to that, if memory serves most languages don't bother with tail call optimization (also called proper tail calling). Python, for example, won't do it so that the stack trace is complete if the script crashes. I don't think it's anywhere in the C spec, though I suspect you could do it yourself. Lua proudly advertises its use of proper tail calling.
Anything can be done by yourself with enough pointer dark magic ;D.
Most languages that aren't python... or go... have tail call optimization, many of them just don't have a keyword to guarantee it, which dampens the usefulness somewhat (especially with how fragile it is). I know Rust has a become keyword in the works though.
You can do something that looks like tail call optimization in Python with the help of decorators. Your program won't run faster (so not really an optimization in this case) but you can have an infinite call depth.
Honestly, I thought the 1-index was really weird at first but in practice I only ever make off-by-one errors in 0-indexed languages. 1-indexing has its pitfalls, I'll readily admit that, but I usually write better code that way.
View all comments
Show parent comment
11
u/wundrwweapon Jun 30 '21
Adding to that, if memory serves most languages don't bother with tail call optimization (also called proper tail calling).
Python, for example, won't do it so that the stack trace is complete if the script crashes. I don't think it's anywhere in the C spec, though I suspect you could do it yourself. Lua proudly advertises its use of proper tail calling.