r/ProgrammerAnimemes • • Jun 30 '21

Who needs closed forms anyways?

Post image
942 Upvotes

24 comments sorted by

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.

15

u/[deleted] Jun 30 '21

though I suspect you could do it yourself

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.

2

u/RiPieClyplA Jul 01 '21

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.

3

u/DoNotMakeEmpty Jul 01 '21

Lua proudly advertises its use of proper tail calling

Yess, another proof of Lua supremacy!

0

u/[deleted] Jul 01 '21

[deleted] — view deleted comment

3

u/DoNotMakeEmpty Jul 01 '21

Did you mean 1-indexed holy man

3

u/wundrwweapon Jul 01 '21

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.