[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Problem with Python's 'yield'



At 6:22 PM -0400 5/27/03, Eric Kidd wrote:
>On Tue, 2003-05-27 at 14:09, Dan Sugalski wrote:
>>  At 11:15 AM -0400 5/27/03, Eric Kidd wrote:
>>  >We can shorten the code--and make it run in O(N) time--by adding a new
>>  >keyword to replace the "for v in ...: yield v" pattern:
>>
>>  Color me confused here, but are you proposing to yield out of
>>  multiple levels of the call at once, or to yield multiple values at
>>  once, or to yield multiple values but store them up and parcel them
>>  out one per call?
>
>I'm proposing to yield straight from the leaves of the tree to the
>ultimate consumer, instead of yielding and re-yielding each value up the
>tree one step at a time.  Passing each leaf value up to the root adds an
>extra O(log N) factor to the algorithm, which is just silly.

Oh, sure. I wasn't quite sure what you were looking for. The general 
case of yielding out of your caller (or its caller, or the caller 
above that) has a number of issues, but I'd not thought about a 
tail-yield. As, I suppose, does calling into an active coroutine, so 
what's one more issue? :)
-- 
                                         Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan@sidhe.org                         have teddy bears and even
                                       teddy bears get drunk