Nick Coghlan wrote: > This bloats the generated byte code horribly, though - it is necessary to > produce two complete copies of the for loop code, since we don't know at > compile > time which version (finalising or non-finalising) will be needed.
Unless I'm seriously mistaken, all the Python-equivalent loop code that's been presented is only for expositional purposes -- in real life, the logic would be embedded in the ceval code that implements the for-loop control bytecodes, so there would be little or no difference in the bytecode from what is generated today. > It also takes away from the programmer the ability to choose to do partial > iteration on generators that require finalisation. > > Accordingly, I switched to a version which puts control pack in the hands of > the > programmer. I still think it puts far too much burden on the user, though. The vast majority of the time, for-loops are intended to consume their iterators, and the user may not even know what flavour of iterator is being used, much less want to have to think about it. This means that nearly *every* for-loop would need to have a finally tacked on the end of it as a matter of course. It would be better to do it the other way around, and have a different form of looping statement for when you *don't* want finalization. The programmer knows he's doing a partial iteration when he writes the code, and is therefore in a position to choose the right statement. For backwards compatibility, the existing for-loop would work for partial iteration of old iterators, but this usage would be deprecated. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | [EMAIL PROTECTED] +--------------------------------------+ _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com