[Python-Dev] PEP 340: Else clause for block statements

Aahz aahz at pythoncraft.com
Sun May 1 15:43:34 CEST 2005


On Sun, May 01, 2005, Nick Coghlan wrote:
>
> Option 0:
>    No else clause allowed. Figured I should mention this, since it is 
>    Guido's last reported inclination, and my total lack of use cases for the 
> other options below suggests this is the best idea for an initial 
> implementation.

+1

> Option 1: mimic try, for, while semantics
>    An 'else' clause on a block statement behaves like the else clause on 
>    for and while loops, and on try/except statements - the clause is executed 
> only if the managed suite completes 'normally' (i.e. it is not terminated 
> early due to an exception, a break statement or a return statement)

+0

> Option 2: mimic if semantics
>   An 'else' clause on a block statement behaves vaguely like the else 
>   clause on an if statement - the clause is executed only if the first suite 
> is never entered, but no exception occurs (i.e. StopIteration is raised by 
> the first call to next).

-0

> Option 3: iterator-controlled semantics
>   The iterator is given the ability to control whether or not the else 
>   clause is executed (e.g. via an attribute of StopIteration), probably using 
> option 1 above as the default behaviour.

-1

Did you deliberately sort the options this way?  ;-)  I'm mainly
responding to deliver my vote against option 3; I don't care much about
the other possibilities.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It's 106 miles to Chicago.  We have a full tank of gas, a half-pack of
cigarettes, it's dark, and we're wearing sunglasses."  "Hit it."


More information about the Python-Dev mailing list