[Python-ideas] A Continuations Compromise in Python

Scott David Daniels Scott.Daniels at Acm.Org
Mon May 4 00:21:19 CEST 2009


Arnaud Delobelle wrote:
> 2009/5/3 Steven D'Aprano <steve at pearwood.info>:
> 
>> Guido's largest objection to TCO is that it ruins nice stack traces when
>> you get an exception. I must admit I've never understood this argument.
>> Perhaps I'm missing something, but I've never considered the stack
>> trace you get in recursive functions useful. Here's an example:
>>
>>>>> def spam(n=0):
>> ...     if n == 10: raise ValueError(
>> ...     'Nobody expects the Spanish Inquisition!')
>> ...     spam(n+1)

Right, but if you have more than one tail call, you lose the
history of _which_ recursive call was taken.  If you are saying,
"Only a single tail-recursive call is allowed per function,"
then you are eliminating solution by cases.  Think:
         def recurse(source):
             if branching(source):
                     if goleft(source):
                         return recurse(source[0])
                     else:
                         return recurse(source[1:])
             return source

--Scott David Daniels
Scott.Daniels at Acm.Org




More information about the Python-ideas mailing list