Is this PEP-able? fwhile
On Tuesday, June 25, 2013 9:30:54 PM UTC+5:30, Ian wrote: In my experience the sorts of people who preach one exit point are also all about defining preconditions and postconditions and proving that the postconditions follow from the preconditions. I think that the two are linked, because the one exit point rule makes those sorts of proofs simpler. Ah! utopia! For every one who knows about pre/post/invariant conditions, there are 10 who follow goto-statement-is-harmful like a religious edict. I just checked and MISRA-C 2012 now allows gotos in specific, limited circumstances. I think it was the MISRA-C 1998 standard that caused all this trouble. So if MISRA now allows goto, why not Python :) -- http://mail.python.org/mailman/listinfo/python-list
Is this PEP-able? fwhile
Syntax: fwhile X in ListY and conditionZ: There is precedent in Algol 68: for i from 0 to n while safe(i) do .. od which would also make a python proposal that needs no new key words: for i in range(n) while safe(i): .. The benefit of the syntax would be to concentrate the code expressing the domain of the loop rather than have it in separate locations. Not a big win in my opinion. Neil Neil, I disagree. The problem IMO is that python 'for's are a different kind of 'for' in that they have no explicit indexing and no explicit range test; just a list which has elements drawn from it. This is amazingly powerful and concise. Unfortunately, the breaks are just gotos community often ruins this conciseness by going to 'while' or itertools (or worse) to avoid adding a break to a 'for' which needs to be terminated early. I think suggestions like yours and Fabio's are good ones. If 'for' has an 'else', why not a 'while'? FWIW, I can sympathize with the 'no breaks or continues' notion, at least largely so. That said, I have used gotos sparingly in C. The problem is that applying the no-breaks notion to the python 'for' is problematic because as I said earlier, the python 'for' is a special kind of 'for'. Maybe Guido needs to be seen in public hugging a break statement. :) -- http://mail.python.org/mailman/listinfo/python-list
Is this PEP-able? fwhile
Ian, Regarding your first message breaks are anathema (for many) and your other alternative is complicated. Regarding your second post, anding of lists is allowed, but generally returns non-utile results, but point taken. I guess technically it could be the last statement, with the condition just being ListD in your example. To make the condition more complex (in your example) you'd have to add parens. -- http://mail.python.org/mailman/listinfo/python-list
Is this PEP-able? fwhile
Syntax: fwhile X in ListY and conditionZ: The following would actually exactly as: for X in ListY: fwhile X in ListY and True: fwhile would act much like 'for', but would stop if the condition after the 'and' is no longer True. The motivation is to be able to make use of all the great aspects of the python 'for' (no indexing or explict end condition check, etc.) and at the same time avoiding a 'break' from the 'for'. (NOTE: Many people are being taught to avoid 'break' and 'continue' at all costs, so they instead convert the clean 'for' into a less-clean 'while'. Or they just let the 'for' run out. You can argue against this teaching (at least for Python) but that doesn't mean it's not prevalent and prevailing.) [People who avoid the 'break' by functionalizing an inner portion of the loop are just kidding themselves and making their own code worse, IMO.] I'm not super familiar with CPython, but I'm pretty sure I could get this up and working without too much effort. The mandatory 'and' makes sense because 'or' would hold the end value valid (weird) and not accomplish much. The condition itself could of course have multiple parts to it, including 'or's. It's possible the name 'fwhile' is not optimal, but that shouldn't affect the overall merit/non-merit of the concept. Comments and Questions welcome. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this PEP-able? fwhile
I find itertools clumsy and wordy. You shouldn't have to have a lambda expression just to break out of a for! I agree to not cater to bad practices, but if a clean improvement is possible it will practically help code overall, even if theoretically people shouldn't be adopting a practice (don't use breaks) to the wrong circumstance (the python 'for' is not like other fors in other languages). -Jim -Original Message- From: Joshua Landau joshua.landau...@gmail.com To: jimjhb jim...@aol.com Cc: python-list python-list@python.org Sent: Mon, Jun 24, 2013 4:41 pm Subject: Re: Is this PEP-able? fwhile On 24 June 2013 20:52, jim...@aol.com wrote: Syntax: fwhile X in ListY and conditionZ: The following would actually exactly as: for X in ListY: fwhile X in ListY and True: fwhile would act much like 'for', but would stop if the condition after the 'and' is no longer True. The motivation is to be able to make use of all the great aspects of the python 'for' (no indexing or explict end condition check, etc.) and at the same time avoiding a 'break' from the 'for'. There is one good reason not to use breaks: itertools. I often prefer a for-over-a-properly-constrained-iterable to a for-with-a-break, but there's no real reason to ever prefer a while. That said, why add this to the syntax when there's already functionality that gives you what you want? Just use itertools.takewhile as Ian Kelly says. (NOTE: Many people are being taught to avoid 'break' and 'continue' at all costs, so they instead convert the clean 'for' into a less-clean 'while'. Or they just let the 'for' run out. You can argue against this teaching (at least for Python) but that doesn't mean it's not prevalent and prevailing.) We shouldn't make a language around people are taught the language badly - let us accommodate for their bad practices! [People who avoid the 'break' by functionalizing an inner portion of the loop are just kidding themselves and making their own code worse, IMO.] I'm not super familiar with CPython, but I'm pretty sure I could get this up and working without too much effort. The mandatory 'and' makes sense because 'or' would hold the end value valid (weird) and not accomplish much. The condition itself could of course have multiple parts to it, including 'or's. It's possible the name 'fwhile' is not optimal, but that shouldn't affect the overall merit/non-merit of the concept. Possible? It's more than just possible, *wink*. Comments and Questions welcome. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this PEP-able? fwhile
Your syntax makes great sense. Avoiding new keywords is obviously preferable. -Original Message- From: Fábio Santos fabiosantos...@gmail.com To: jimjhb jim...@aol.com Cc: python-list python-list@python.org Sent: Mon, Jun 24, 2013 4:34 pm Subject: Re: Is this PEP-able? fwhile On Mon, Jun 24, 2013 at 8:52 PM, jim...@aol.com wrote: Syntax: fwhile X in ListY and conditionZ: The following would actually exactly as: for X in ListY: fwhile X in ListY and True: fwhile would act much like 'for', but would stop if the condition after the 'and' is no longer True. The motivation is to be able to make use of all the great aspects of the python 'for' (no indexing or explict end condition check, etc.) and at the same time avoiding a 'break' from the 'for'. (NOTE: Many people are being taught to avoid 'break' and 'continue' at all costs, so they instead convert the clean 'for' into a less-clean 'while'. Or they just let the 'for' run out. You can argue against this teaching (at least for Python) but that doesn't mean it's not prevalent and prevailing.) [People who avoid the 'break' by functionalizing an inner portion of the loop are just kidding themselves and making their own code worse, IMO.] I'm not super familiar with CPython, but I'm pretty sure I could get this up and working without too much effort. The mandatory 'and' makes sense because 'or' would hold the end value valid (weird) and not accomplish much. The condition itself could of course have multiple parts to it, including 'or's. It's possible the name 'fwhile' is not optimal, but that shouldn't affect the overall merit/non-merit of the concept. Comments and Questions welcome. Thanks. I can see where you are coming from, but this is probably not going to happen. The and keyword is also Also, the (amazing) python devs are concerned with overcomplicating the language syntax, which is bad for: newbies, other implementations of the language, and code readability. The syntax doesn't seem too obvious, and there is a new keyword, fwhile. This can probably be best achieved by adding to the existing for loop, so maybe taking advantage of the existing for...if syntax and adding for...while would be a better idea? So, maybe: for x in y while cond: And for list/set/dict comprehensions and generator expressions: [x for x in range(123) while cond] Just maybe. -- Fábio Santos -- http://mail.python.org/mailman/listinfo/python-list