Possibly Pythonic Tail Call Optimization (TCO/TRE)
steve at pearwood.info
Thu Jul 16 20:58:54 CEST 2015
On Fri, 17 Jul 2015 03:34 am, Joonas Liik wrote:
> Now i admit that it is possible to have infinite recursion but it is
> also possiblew to have infinite loops. and we don't kill your code
> after 1000 iterations of a while loop so why should we treat recursion
> any differently?
Because a while loop which repeats to many times is annoying but harmless,
but a function that recurses too many times will blow up the stack and
cause a seg fault, possibly executing arbitrary memory as code. You want
malware and viruses to take over your system? That's how you get malware
and viruses to take over your system.
> Having a user defined maximum stack limit might be a good idea, eg if
> my stack takes up 100MB its prolly broke, but it should be my duty as
> a programmer to specify such a limit, not have it inflicted upon me
> (worse, in a manner that cannot be changed!).
You mean sys.getrecursionlimit() and sys.setrecursionlimit()?
More information about the Python-list