[Python-Dev] PEP 340: Deterministic Finalisation (new PEP draft, either a competitor or update to PEP 340)
Nick Coghlan
ncoghlan at gmail.com
Mon May 9 23:51:03 CEST 2005
Raymond Hettinger wrote:
> [Nick Coghlan]
>
>>The number of good use cases for a looping block statement currently
>>stands at
>>exactly 1 (auto_retry). Every other use case suggested (locking,
>
> opening,
>
>>suppressing, etc) involves factoring out try statement boiler plate
>
> that
>
>>is far
>>easier to comprehend with a single pass user defined statement.
>
>
> I would like to offer up one additional use case, eliminating redundant
> code in a do-while construct:
>
>
> def do_while(cond_func):
> yield
> while cond_func():
> yield
>
> block do_while(lambda: a>b):
> <sequence of actions affecting a and b>
Nice example, but it doesn't need to intercept exceptions the way auto_retry
does. Accordingly, a 'for' loop which makes [VAR in] optional would do the job
just fine:
for do_while(lambda: a>b):
<do it>
Even today, the following works:
def do_while(cond_func):
yield None
while cond_func():
yield None
for _ in do_while(lambda: a>b):
<do it>
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
More information about the Python-Dev
mailing list