[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-26 Thread Rob Cliffe via Python-ideas
On 25/07/2020 20:11, Christopher Barker wrote: On Sat, Jul 25, 2020 at 4:39 AM Eric V. Smith > wrote: On 7/25/2020 7:28 AM, Chris Angelico wrote: > Do you REALLY think that everyone will automatically understand it > just because it's spelled "for... then

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Eric V. Smith
On 7/25/2020 3:11 PM, Christopher Barker wrote: On Sat, Jul 25, 2020 at 4:39 AM Eric V. Smith > wrote: But all of these always make me wonder about a return inside the suite. Does the "else" part execute (answer: no). So as a rule, I avoid the construc

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread David Mertz
On Sat, Jul 25, 2020, 3:12 PM Christopher Barker > I'm not advocating for any change (Obviously :-) ) -- but if there were to > be one, I"d strongly vote for some version of else not break or else if > not break because it introduces no keywords, and it's a lot more > compatible documentation-wise

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Greg Ewing
How about we just document the whole feature as deprecated and never speak of it again? -- Greg ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Christopher Barker
On Sat, Jul 25, 2020 at 4:39 AM Eric V. Smith wrote: > On 7/25/2020 7:28 AM, Chris Angelico wrote: > > Do you REALLY think that everyone will automatically understand it > > just because it's spelled "for... then" instead of "for... else"? > > I wouldn't find "for ... then" any less confusing tha

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Eric V. Smith
On 7/25/2020 7:28 AM, Chris Angelico wrote: Do you REALLY think that everyone will automatically understand it just because it's spelled "for... then" instead of "for... else"? I wouldn't find "for ... then" any less confusing than "for ... else". I do find "for ... else if not break" easier t

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Chris Angelico
On Sat, Jul 25, 2020 at 7:18 PM Steven D'Aprano wrote: > > On Sat, Jul 25, 2020 at 11:40:06AM +1000, Chris Angelico wrote: > > > And a lot of style guides will say "prefer > > else because it's compatible with more Python versions". > > Like they did in Python 2 when we had two ways of getting the

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Paul Sokolovsky
Hello, On Sat, 25 Jul 2020 18:44:55 +1000 Steven D'Aprano wrote: [] > I fear that even if we could get the average developer to say "I > know, let's use `ideas` to write a DSL", the project manager -- and > the rest of the team -- will probably respond "Over my dead body". > We're a long, long

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Steven D'Aprano
On Sat, Jul 25, 2020 at 11:40:06AM +1000, Chris Angelico wrote: > And a lot of style guides will say "prefer > else because it's compatible with more Python versions". Like they did in Python 2 when we had two ways of getting the next element from an iterator? # Python 2.7 py> it = iter

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Steven D'Aprano
On Sat, Jul 25, 2020 at 12:49:36PM +1000, Chris Angelico wrote: > On Sat, Jul 25, 2020 at 12:09 PM André Roberge > wrote: > > Already done (with a different keyword): > > > > https://aroberge.github.io/ideas/docs/html/nobreak.html > > That's a very nice project André, and I think it will probab

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread Rob Cliffe via Python-ideas
On 25/07/2020 07:59, David Mertz wrote: On Thu, Jul 23, 2020, 9:19 PM Rob Cliffe via Python-ideas The upholders of the status quo regularly provide gallant explanations of why "else" is perfectly natural, even intuitive. They remind me of these two mathematicians: M1: This result is

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-25 Thread David Mertz
On Thu, Jul 23, 2020, 9:19 PM Rob Cliffe via Python-ideas > The upholders of the status quo regularly provide gallant explanations of > why "else" is perfectly natural, even intuitive. > The fact is, it isn't. If it were, it wouldn't **need** to be repeatedly > explained by gurus to lesser mortal

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-24 Thread Chris Angelico
On Sat, Jul 25, 2020 at 12:09 PM André Roberge wrote: > > > > On Fri, Jul 24, 2020 at 10:43 PM Chris Angelico wrote: > SNIP >> >> >> > If we had some sort of easy to use standard library support for >> > transpiling code, then your advice could actually be practical and not >> > just dismissive.

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-24 Thread André Roberge
On Fri, Jul 24, 2020 at 10:43 PM Chris Angelico wrote: SNIP > > > If we had some sort of easy to use standard library support for > > transpiling code, then your advice could actually be practical and not > > just dismissive. "Pft, if you don't like it, write your own language" is > > not exactly

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-24 Thread Chris Angelico
On Sat, Jul 25, 2020 at 11:13 AM Steven D'Aprano wrote: > > On Thu, Jul 23, 2020 at 07:22:51AM +1000, Chris Angelico wrote: > > > Please, everyone, can we NOT keep coming up with ideas that are > > basically "let's invent a new spelling for exactly the same thing, > > with no benefits, > > Surely

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-24 Thread Steven D'Aprano
On Thu, Jul 23, 2020 at 07:22:51AM +1000, Chris Angelico wrote: > Please, everyone, can we NOT keep coming up with ideas that are > basically "let's invent a new spelling for exactly the same thing, > with no benefits, Surely having a less confusing and misleading spelling is a benefit. We like

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-24 Thread Mathew Elman
On Thu, 23 Jul 2020 at 16:25, Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Mathew Elman writes: > > > Frankly, saying that a part of a language that is frequently > > misunderstood, is *never* allowed to be improved is disappointing > > when the suggestion that it can be

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-24 Thread Barry Scott
> On 23 Jul 2020, at 17:04, Rob Cliffe via Python-ideas > wrote: > > > > On 23/07/2020 16:24, Stephen J. Turnbull wrote: >> Steven D'Aprano writes: >> > On Wed, Jul 22, 2020 at 06:14:39AM +0300, Paul Sokolovsky wrote: >> >> > > But no, loop executes, *or else* the following "else" block >

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-24 Thread Paul Moore
On Fri, 24 Jul 2020 at 02:18, Rob Cliffe via Python-ideas wrote: > The upholders of the status quo regularly provide gallant explanations of why > "else" is perfectly natural, even intuitive. > The fact is, it isn't. If it were, it wouldn't *need* to be repeatedly > explained by gurus to lesse

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-23 Thread Rob Cliffe via Python-ideas
On 23/07/2020 16:24, Stephen J. Turnbull wrote: Steven D'Aprano writes: > On Wed, Jul 22, 2020 at 06:14:39AM +0300, Paul Sokolovsky wrote: > > But no, loop executes, *or else* the following "else" block > > executes ;-). He means the loop *suite* executes (this includes "getting to" a

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-23 Thread Rob Cliffe via Python-ideas
On 23/07/2020 16:24, Stephen J. Turnbull wrote: Steven D'Aprano writes: > On Wed, Jul 22, 2020 at 06:14:39AM +0300, Paul Sokolovsky wrote: > > But no, loop executes, *or else* the following "else" block > > executes ;-). He means the loop *suite* executes (this includes "getting to" a b

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-23 Thread Stephen J. Turnbull
Mathew Elman writes: > Frankly, saying that a part of a language that is frequently > misunderstood, is *never* allowed to be improved is disappointing > when the suggestion that it can be (somehow) has been so well > received by everyone else. The highly improbable is frequently well-receive

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-23 Thread Stephen J. Turnbull
Steven D'Aprano writes: > On Wed, Jul 22, 2020 at 06:14:39AM +0300, Paul Sokolovsky wrote: > > But no, loop executes, *or else* the following "else" block > > executes ;-). He means the loop *suite* executes (this includes "getting to" a break statement or other control flow that leaves the lo

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Rob Cliffe via Python-ideas
On 22/07/2020 22:22, Chris Angelico wrote: On Thu, Jul 23, 2020 at 7:06 AM João Matos wrote: Hello, Why not just use Raymond's suggestion nobreak as a replacement of the else in loops and deprecate the else in Python 4? There is at least a precedent when not equal <> was deprecated in favor

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread João Matos
Hello, Maybe I didn't explain it correctly. What I meant was to do exactly the same that happened with <>/!=. That is, add nobreak in Py3 (allowing the use of both else/nobreak) and only deprecate else in Py4. João Matos On 22/07/2020 22:22, Chris Angelico wrote: On Thu, Jul 23, 2020 at 7:06

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Chris Angelico
On Thu, Jul 23, 2020 at 7:06 AM João Matos wrote: > > Hello, > > Why not just use Raymond's suggestion nobreak as a replacement of the else in > loops and deprecate the else in Python 4? > There is at least a precedent when not equal <> was deprecated in favor of != > from Py2 to Py3. > We could

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread João Matos
Hello, Why not just use Raymond's suggestion nobreak as a replacement of the else in loops and deprecate the else in Python 4? There is at least a precedent when not equal <> was deprecated in favor of != from Py2 to Py3. We could do the same with else/nobreak between Py3 and Py4. João Matos

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Mathew Elman
On Wed, 22 Jul 2020 at 13:45, Paul Moore wrote: > On Wed, 22 Jul 2020 at 13:18, Mathew Elman wrote: > >> Ones that retain else on loops are bad because > >> they end up providing two (typically equally confusing) ways of doing > >> things. > > > > I don't think this is the case. I agree that add

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Paul Moore
On Wed, 22 Jul 2020 at 13:18, Mathew Elman wrote: >> Ones that retain else on loops are bad because >> they end up providing two (typically equally confusing) ways of doing >> things. > > I don't think this is the case. I agree that adding an alternative to `else` > just to have an alternative is

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Mathew Elman
On Wed, 22 Jul 2020 at 12:24, Paul Moore wrote: > On Wed, 22 Jul 2020 at 10:54, Stestagg wrote: > > > > I'm (weakly) +1 for the concept of for..else being confusing, weird, and > somehow not quite suitable/useful for many use-cases where it feels like it > should. > > > > I'm -1 for each of the

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Paul Sokolovsky
Hello, On Wed, 22 Jul 2020 20:00:29 +1000 Steven D'Aprano wrote: [] > > > py> for x in [1,2]: > > > ... print("inside loop") > > > ... else: > > > ... print("elif never looped") > > > ... > > > inside loop > > > inside loop > > > elif never looped >

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Paul Moore
On Wed, 22 Jul 2020 at 10:54, Stestagg wrote: > > I'm (weakly) +1 for the concept of for..else being confusing, weird, and > somehow not quite suitable/useful for many use-cases where it feels like it > should. > > I'm -1 for each of the suggested improvements that I've understood so far. > > I

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Steven D'Aprano
On Tue, Jul 21, 2020 at 05:48:35PM -0700, Christopher Barker wrote: > for something in some_iterable: > some_stuff_with_maybe_a_break > else: # if not break: > something_more > > and no changes needed to Python! > > I may actually start doing that myself ... I always do that, not becau

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Steven D'Aprano
On Wed, Jul 22, 2020 at 06:14:39AM +0300, Paul Sokolovsky wrote: > Hello, > > On Wed, 22 Jul 2020 09:45:31 +1000 > Steven D'Aprano wrote: > > > On Tue, Jul 21, 2020 at 10:07:47PM +0100, Barry wrote: > > > > > 1. Because that not what else mean today. Its elif never looped. > > > > > > p

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Stestagg
I'm (weakly) +1 for the concept of for..else being confusing, weird, and somehow not quite suitable/useful for many use-cases where it feels like it should. I'm -1 for each of the suggested improvements that I've understood so far. I agree that the suggested 'ban' on changes in this area is proba

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-22 Thread Mathew Elman
On Wed, 22 Jul 2020 at 04:47, Paul Sokolovsky wrote: > Hello, > > On Tue, 21 Jul 2020 17:48:35 -0700 > Christopher Barker wrote: > > > how about: > > > > for something in some_iterable: > > some_stuff_with_maybe_a_break > > else if not break: > > something_more > > > > No new keywords :-

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Christopher Barker
> I find the need for that regularly. And I use the obvious syntax which > everyone else uses: > > if not seq: > print("This page is intentionally left blank") > else: > for i in seq: > ... Not so easy for an iterator though. I’m more likely to do something like this: Page = New

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Chris Angelico
On Wed, Jul 22, 2020 at 1:15 PM Paul Sokolovsky wrote: > > Hello, > > On Wed, 22 Jul 2020 09:45:31 +1000 > Steven D'Aprano wrote: > > > On Tue, Jul 21, 2020 at 10:07:47PM +0100, Barry wrote: > > > > > 1. Because that not what else mean today. Its elif never looped. > > > > > > py> for x in [1

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Paul Sokolovsky
Hello, On Tue, 21 Jul 2020 17:48:35 -0700 Christopher Barker wrote: > how about: > > for something in some_iterable: > some_stuff_with_maybe_a_break > else if not break: > something_more > > No new keywords :-) > > or: > > for something in some_iterable: > some_stuff_with_maybe_a

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Paul Sokolovsky
Hello, On Wed, 22 Jul 2020 09:45:31 +1000 Steven D'Aprano wrote: > On Tue, Jul 21, 2020 at 10:07:47PM +0100, Barry wrote: > > > 1. Because that not what else mean today. Its elif never looped. > > > py> for x in [1,2]: > ... print("inside loop") > ... else: > ... p

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Christopher Barker
how about: for something in some_iterable: some_stuff_with_maybe_a_break else if not break: something_more No new keywords :-) or: for something in some_iterable: some_stuff_with_maybe_a_break else: # if not break: something_more and no changes needed to Python! I may actuall

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Ethan Furman
On 7/20/20 7:34 AM, Barry Scott wrote: To avoid the ambiguity of `if` after `for` why not follow `for` with `elif`? for x in ...: ... elif break: # break was called elif not break: # looped at least once and break not used elif pass: # same as else today # loop'ed no times (I always have to t

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Rob Cliffe via Python-ideas
On 22/07/2020 00:29, MRAB wrote: On 2020-07-22 00:02, Rob Cliffe via Python-ideas wrote: On 21/07/2020 22:07, Barry wrote: On 21 Jul 2020, at 18:47, Rob Cliffe via Python-ideas wrote:  On Mon, Jul 20, 2020 at 03:22 Jonathan Fine > wrote:     This is a continua

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Steven D'Aprano
On Tue, Jul 21, 2020 at 10:07:47PM +0100, Barry wrote: > 1. Because that not what else mean today. Its elif never looped. py> for x in [1,2]: ... print("inside loop") ... else: ... print("elif never looped") ... inside loop inside loop elif never looped

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread MRAB
On 2020-07-22 00:02, Rob Cliffe via Python-ideas wrote: On 21/07/2020 22:07, Barry wrote: On 21 Jul 2020, at 18:47, Rob Cliffe via Python-ideas wrote:  On Mon, Jul 20, 2020 at 03:22 Jonathan Fine > wrote: This is a continuation of my previous post to this thr

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Rob Cliffe via Python-ideas
On 21/07/2020 22:07, Barry wrote: On 21 Jul 2020, at 18:47, Rob Cliffe via Python-ideas wrote:  On Mon, Jul 20, 2020 at 03:22 Jonathan Fine > wrote: This is a continuation of my previous post to this thread. Python's FOR ... ELSE ... , Raymond Hetti

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Barry
> On 21 Jul 2020, at 18:47, Rob Cliffe via Python-ideas > wrote: > >  > On Mon, Jul 20, 2020 at 03:22 Jonathan Fine wrote: >> This is a continuation of my previous post to this thread. >> >> Python's FOR ... ELSE ... , Raymond Hettinger has told us, has origins in >> some ideas of Don Knut

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Rob Cliffe via Python-ideas
On Mon, Jul 20, 2020 at 03:22 Jonathan Fine > wrote: This is a continuation of my previous post to this thread. Python's FOR ... ELSE ... , Raymond Hettinger has told us, has origins in some ideas of Don Knuth. That’s news to me (both that it’s due to Knuth

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Rob Cliffe via Python-ideas
On 20/07/2020 09:56, Alex Hall wrote: On Mon, Jul 20, 2020 at 10:36 AM Rob Cliffe via Python-ideas mailto:python-ideas@python.org>> wrote: May I repeat:  Spelling 'if break:' and 'if not break:' rather than say 'on_break:' etc. would avoid adding new keywords. I don't know wh

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-21 Thread Rob Cliffe via Python-ideas
On 14/07/2020 04:56, Random832 wrote: On 11/07/2020 06:22, Олег Комлев wrote: ELSE-clause in FOR and WHILE has unclear syntax. I suggest new clause instead: if COND: ... [elif COND: ...] [else: ...] This IF-clause like must be immediately after FOR- or WHILE-cycle (only comment allo

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Rob Cliffe via Python-ideas
I don't know what to do about the zero iterations case, though. Perhaps simply `if not:' Best wishes Rob Cliffe ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.o

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Guido van Rossum
Also, let me be clear that this feature will never be added to the language. On Mon, Jul 20, 2020 at 07:36 Guido van Rossum wrote: > On Mon, Jul 20, 2020 at 03:22 Jonathan Fine wrote: > >> This is a continuation of my previous post to this thread. >> >> Python's FOR ... ELSE ... , Raymond Hetti

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Guido van Rossum
On Mon, Jul 20, 2020 at 03:22 Jonathan Fine wrote: > This is a continuation of my previous post to this thread. > > Python's FOR ... ELSE ... , Raymond Hettinger has told us, has origins in > some ideas of Don Knuth. > That’s news to me (both that it’s due to Knuth and that Raymond said so). I i

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Barry Scott
> On 20 Jul 2020, at 09:56, Alex Hall wrote: > > On Mon, Jul 20, 2020 at 10:36 AM Rob Cliffe via Python-ideas > mailto:python-ideas@python.org>> wrote: > May I repeat: Spelling 'if break:' and 'if not break:' rather than say > 'on_break:' etc. would avoid adding new keywords. > > I don't kn

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Jonathan Fine
This is a continuation of my previous post to this thread. Python's FOR ... ELSE ... , Raymond Hettinger has told us, has origins in some ideas of Don Knuth. For that reason, and others, I'll concisely review these ideas. In the very early days, a computer program was a sequence of commands. The

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Alex Hall
On Mon, Jul 20, 2020 at 10:36 AM Rob Cliffe via Python-ideas < python-ideas@python.org> wrote: > May I repeat: Spelling 'if break:' and 'if not break:' rather than say > 'on_break:' etc. would avoid adding new keywords. > > I don't know what to do about the zero iterations case, though. > It cou

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Mathew Elman
On Sun, 19 Jul 2020 at 15:43, Олег Комлев wrote: > Thank to all disputants. > It is possible to borrow the keyword "case" from PEP-622 (when it appears > https://www.python.org/dev/peps/pep-0622). Keyword "case" can be written > instead of "else/elif". I.e. > case COND: > ... > [case COND: >

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-20 Thread Rob Cliffe via Python-ideas
On 15/07/2020 09:20, Dominik Vilsmeier wrote: But `finally` with a `for` loop is redundant since the code can be placed just after the loop. For `try/except` it's a different situation since the exception might bubble up, so "normal" code after the `try` won't be reached. +1 Also `on_bre

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-19 Thread Олег Комлев
Thank to all disputants. It is possible to borrow the keyword "case" from PEP-622 (when it appears https://www.python.org/dev/peps/pep-0622). Keyword "case" can be written instead of "else/elif". I.e. case COND: ... [case COND: ...] [case COND: ...] All conditions COND must be different. L

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-15 Thread Random832
On Tue, Jul 14, 2020, at 17:55, Rob Cliffe wrote: > > What if "instead of a special kind of if clause that can only be placed > > after a loop", we simply defined these three special expressions [usable in > > any if/elif statement] to reference special boolean flags that are set > > after exiti

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-15 Thread Steven D'Aprano
On Wed, Jul 15, 2020 at 05:45:05AM +, Steve Barnes wrote: > Can I suggest that for loops the `else` would be a lot clearer if it > was spelt `finally` as was done for PEP-0341 for try blocks and that > we might possibly need one or more `on_…` clauses such as `on_break` > and `on_finish` I

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-15 Thread Jonathan Fine
I'm really glad that Олег Комлев has posted this suggestion to the list. Thank you! I found myself using this construction, and in December 2019 (that seems a long time ago) I discussed it face-to-face with Paul Piwek. He found this highly relevant article https://stackoverflow.com/questions/99799

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-15 Thread Mathew Elman
The point is that `for-else` reads like "do this for loop ELSE (or but if you can't loop) do this", i.e. roughly equivalent to this: > try: > loop_entered = False > for loop_entered, elem in enumerate(iterable, start=1): >pass > assert loop_entered > except AssertionError: >

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-15 Thread Dominik Vilsmeier
But `finally` with a `for` loop is redundant since the code can be placed just after the loop. For `try/except` it's a different situation since the exception might bubble up, so "normal" code after the `try` won't be reached. Also `on_break` doesn't seem really important since that code can be e

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-14 Thread Mathew Elman
But in `for...else` the `else` call isn't always called, so changing `else` for `finally` doesn't make sense. What you're suggesting is replacing `else` with `on_finish` and adding `finally` and `on_break`. I agree that having `finally` could make the use cases of `else` clearer, but I am not conv

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-14 Thread Steve Barnes
Can I suggest that for loops the `else` would be a lot clearer if it was spelt `finally` as was done for PEP-0341 for try blocks and that we might possibly need one or more `on_…` clauses such as `on_break` and `on_finish` I think that this would be a lot clearer: for i in range(N): if i >

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-14 Thread Mathew Elman
On Tue, 14 Jul 2020 at 12:38, Dominik Vilsmeier wrote: > On 14.07.20 09:54, Mathew Elman wrote: > > What about adding `except` to the compound loop statement? > That way in cases where there needs to be clarity you can raise a specific > exception rather than just `break`. > Keeping the logic of

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-14 Thread Dominik Vilsmeier
On 14.07.20 09:54, Mathew Elman wrote: What about adding `except` to the compound loop statement? That way in cases where there needs to be clarity you can raise a specific exception rather than just `break`. Keeping the logic of why you "break" the loop inside the loop and would also allow mult

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-14 Thread Mathew Elman
What about adding `except` to the compound loop statement? That way in cases where there needs to be clarity you can raise a specific exception rather than just `break`. Keeping the logic of why you "break" the loop inside the loop and would also allow multiple reasons for breaking from a for loop

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-13 Thread Ethan Furman
On 07/11/2020 09:16 PM, Rob Cliffe via Python-ideas wrote: My gut feeling (backed by no evidence) is that dealing with the case of zero iterations is not needed frequently enough to cater for it. My personal experience is that the case of no iterations is frequent enough, and a big enough pa

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-13 Thread Random832
> On 11/07/2020 06:22, Олег Комлев wrote: > > ELSE-clause in FOR and WHILE has unclear syntax. I suggest new clause > > instead: > > if COND: > ... > [elif COND: > ...] > [else: > ...] > > This IF-clause like must be immediately after FOR- or WHILE-cycle (only > comment allowed between).

[Python-ideas] Re: New clause in FOR and WHILE instead of ELSE

2020-07-11 Thread Rob Cliffe via Python-ideas
On 11/07/2020 06:22, Олег Комлев wrote: ELSE-clause in FOR and WHILE has unclear syntax. I suggest new clause instead: if COND: ... [elif COND: ...] [else: ...] This IF-clause like must be immediately after FOR- or WHILE-cycle (only comment allowed between). It looks like a regular