[Python-ideas] Idea: Compressing the stack on the fly

Chris Angelico rosuav at gmail.com
Mon May 27 15:30:37 CEST 2013


On Mon, May 27, 2013 at 9:01 PM, Joao S. O. Bueno <jsbueno at python.org.br> wrote:
> I have a blog post with such a toy - nevertheless, it is just a toy.
> (If ther ewas soem small problem that could be elegantly approached
> in this fashion but not interactively, it could be used in production
> though)

What can tail recursion do that can't be done by reassigning to the
function parameters and 'goto' back to the top? Or, in the absence of
an actual goto, a construct like this:

def tail_recursive_function(some_arg):
  while True:
    # ... code
    if call_self:
      # return tail_recursive_function(some_other_arg)
      some_arg = some_other_arg
      continue
    # ... more code
    # falling off the end:
    break

which basically amounts to a goto but using extra keywords to avoid
the one that people hate. Is there any fundamental difference? I've
never understood there to be any, but I'm only one, and possibly I'm
wrong.

ChrisA


More information about the Python-ideas mailing list