Does Python optimize tail recursion?

后端 未结 6 1041
情深已故
情深已故 2020-11-22 02:30

I have the following piece of code which fails with the following error:

RuntimeError: maximum recursion depth exceeded

I attemp

6条回答
  •  温柔的废话
    2020-11-22 03:21

    The word of Guido is at http://neopythonic.blogspot.co.uk/2009/04/tail-recursion-elimination.html

    I recently posted an entry in my Python History blog on the origins of Python's functional features. A side remark about not supporting tail recursion elimination (TRE) immediately sparked several comments about what a pity it is that Python doesn't do this, including links to recent blog entries by others trying to "prove" that TRE can be added to Python easily. So let me defend my position (which is that I don't want TRE in the language). If you want a short answer, it's simply unpythonic. Here's the long answer:

提交回复
热议问题