Re: Is this PEP-able? fwhile

2013-06-26 Thread Chris Angelico
On Wed, Jun 26, 2013 at 10:47 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 25 Jun 2013 17:20:43 +1000, Neil Hodgson nhodg...@iinet.net.au declaimed the following: jim...@aol.com: Syntax: fwhile X in ListY and conditionZ: There is precedent in Algol 68: for i from 0 to n

Re: Is this PEP-able? fwhile

2013-06-26 Thread jfharden
On Wednesday, 26 June 2013 01:40:22 UTC+1, Dennis Lee Bieber wrote: (hmmm, does any language have a continue that can go to the next iteration of an outer loop?) Perl allows next with a label: perldoc -f next next LABEL nextThe next command is like the continue statement in C; it

Is this PEP-able? fwhile

2013-06-26 Thread jimjhb
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

Re: Is this PEP-able? fwhile

2013-06-26 Thread Fábio Santos
On 26 Jun 2013 11:45, jim...@aol.com wrote: 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

Re: Is this PEP-able? fwhile

2013-06-26 Thread Steven D'Aprano
On Tue, 25 Jun 2013 12:39:53 -0400, jimjhb wrote: 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 :) [humour] You can! Just use the

Re: Is this PEP-able? fwhile

2013-06-26 Thread Neil Cerutti
On 2013-06-25, rusi rustompm...@gmail.com wrote: 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

Re: Is this PEP-able? fwhile

2013-06-26 Thread rusi
On Wednesday, June 26, 2013 6:03:39 PM UTC+5:30, Steven D'Aprano wrote: On Tue, 25 Jun 2013 12:39:53 -0400, jimjhb wrote: 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.

Re: Is this PEP-able? fwhile

2013-06-26 Thread rusi
On Tuesday, June 25, 2013 10:09:53 PM UTC+5:30, jim...@aol.com wrote: 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 :) Not sure who

Re: Is this PEP-able? fwhile

2013-06-26 Thread William Ray Wing
On Jun 26, 2013, at 7:49 AM, Fábio Santos fabiosantos...@gmail.com wrote: On 26 Jun 2013 11:45, jim...@aol.com wrote: 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

Re: Is this PEP-able? fwhile

2013-06-26 Thread Jerry Peters
Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Mon, 24 Jun 2013 19:01:11 -0700 (PDT), rusi rustompm...@gmail.com declaimed the following: On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote: On Tue, Jun 25, 2013 at 5:52 AM, wrote: (NOTE: Many people are being taught

Re: Is this PEP-able? fwhile

2013-06-26 Thread Jan Riechers
On 26.06.2013 16:28, William Ray Wing wrote: On Jun 26, 2013, at 7:49 AM, Fábio Santos fabiosantos...@gmail.com mailto:fabiosantos...@gmail.com wrote: On 26 Jun 2013 11:45, jim...@aol.com mailto:jim...@aol.com wrote: On Tuesday, June 25, 2013 9:30:54 PM UTC+5:30, Ian wrote: In my

Re: Is this PEP-able? fwhile

2013-06-25 Thread rusi
On Tuesday, June 25, 2013 4:44:44 AM UTC+5:30, alex23 wrote: I'd probably just go with a generator expression to feed the for loop: for X in (i for i in ListY if conditionZ): Nice idiom -- thanks Yes it does not correspond to a takewhile (or break in the control

Re: Is this PEP-able? fwhile

2013-06-25 Thread Chris Angelico
On Tue, Jun 25, 2013 at 2:20 PM, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Mon, Jun 24, 2013 at 8:54 PM, Chris Angelico ros...@gmail.com wrote: On Tue, Jun 25, 2013 at 12:01 PM, rusi rustompm...@gmail.com wrote: On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote: On

Re: Is this PEP-able? fwhile

2013-06-25 Thread Neil Hodgson
jim...@aol.com: 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

Re: Is this PEP-able? fwhile

2013-06-25 Thread Joshua Landau
On 25 June 2013 00:13, Tim Chase python.l...@tim.thechases.com wrote: On 2013-06-24 23:39, Fábio Santos wrote: On 24 Jun 2013 23:35, Tim Chase wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement

Re: Is this PEP-able? fwhile

2013-06-25 Thread Joshua Landau
On 24 June 2013 23:50, Chris Angelico ros...@gmail.com wrote: In more free-form languages, I implement this by simply omitting a line-break: ... Python could afford to lose a little rigidity here rather than gain actual new syntax: for i in range(10): if i%3: print(i) And there you

Is this PEP-able? fwhile

2013-06-25 Thread jimjhb
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

Re: Is this PEP-able? fwhile

2013-06-25 Thread Göktuğ Kayaalp
On Mon, Jun 24, 2013 at 11:45:57PM +0100, MRAB wrote: On 24/06/2013 23:35, Chris Angelico wrote: On Tue, Jun 25, 2013 at 8:30 AM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax

Is this PEP-able? fwhile

2013-06-25 Thread jimjhb
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

Re: Is this PEP-able? fwhile

2013-06-25 Thread Terry Reedy
On 6/25/2013 7:17 AM, jim...@aol.com wrote: for i in range(n) while safe(i): .. Combined for-while and for-if statements have been proposed before and rejected. We cannot continuously add simple compositions to the langauge. I disagree. The problem IMO is that python 'for's are a

Re: Is this PEP-able? fwhile

2013-06-25 Thread Ian Kelly
On Mon, Jun 24, 2013 at 2:33 PM, jim...@aol.com wrote: 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

Re: Is this PEP-able? fwhile

2013-06-25 Thread Ian Kelly
On Tue, Jun 25, 2013 at 1:21 AM, Chris Angelico ros...@gmail.com wrote: On Tue, Jun 25, 2013 at 2:20 PM, Benjamin Kaplan benjamin.kap...@case.edu wrote: The reason I was given (which I promptly ignored, of course) is that it's best practice to only have one exit point for a block of code.

Re: Is this PEP-able? fwhile

2013-06-25 Thread rusi
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

Is this PEP-able? fwhile

2013-06-24 Thread jimjhb
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

Re: Is this PEP-able? fwhile

2013-06-24 Thread Ian Kelly
On Mon, Jun 24, 2013 at 1: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.

Re: Is this PEP-able? fwhile

2013-06-24 Thread Ian Kelly
On Mon, Jun 24, 2013 at 1:52 PM, jim...@aol.com wrote: Syntax: fwhile X in ListY and conditionZ: Also, this syntax is ambiguous. Take for example the statement: fwhile X in ListA and ListB and ListC and ListD: At which and does the iterable expression stop and the condition expression

Re: Is this PEP-able? fwhile

2013-06-24 Thread Fábio Santos
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.

Re: Is this PEP-able? fwhile

2013-06-24 Thread Joshua Landau
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

Re: Is this PEP-able? fwhile

2013-06-24 Thread jimjhb
: 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

Re: Is this PEP-able? fwhile

2013-06-24 Thread jimjhb
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

Re: Is this PEP-able? fwhile

2013-06-24 Thread Ian Kelly
On Mon, Jun 24, 2013 at 3:01 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Jun 24, 2013 at 2:34 PM, Fábio Santos fabiosantos...@gmail.com wrote: 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

Re: Is this PEP-able? fwhile

2013-06-24 Thread Ian Kelly
On Mon, Jun 24, 2013 at 2:34 PM, Fábio Santos fabiosantos...@gmail.com wrote: 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? The for...if syntax only exists for

Re: Is this PEP-able? fwhile

2013-06-24 Thread Chris Angelico
On Tue, Jun 25, 2013 at 5:52 AM, jim...@aol.com wrote: (NOTE: Many people are being taught to avoid 'break' and 'continue' at all costs... Why? Why on earth should break/continue be avoided? I think that's the solution: teach people that loops are there to be interrupted and manipulated. And

Re: Is this PEP-able? fwhile

2013-06-24 Thread Tim Chase
On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement it (the 'else:' clause). Use break/continue when appropriate. from minor_gripes import breaking_out_of_nested_loops_to_top_level -tkc --

Re: Is this PEP-able? fwhile

2013-06-24 Thread Chris Angelico
On Tue, Jun 25, 2013 at 8:30 AM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement it (the 'else:' clause). Use break/continue when appropriate. from

Re: Is this PEP-able? fwhile

2013-06-24 Thread Ian Kelly
On Mon, Jun 24, 2013 at 4:41 PM, Fábio Santos fabiosantos...@gmail.com wrote: On 24 Jun 2013 22:29, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Jun 24, 2013 at 2:34 PM, Fábio Santos fabiosantos...@gmail.com wrote: This can probably be best achieved by adding to the existing for loop,

Re: Is this PEP-able? fwhile

2013-06-24 Thread Fábio Santos
On 24 Jun 2013 23:35, Tim Chase python.l...@tim.thechases.com wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement it (the 'else:' clause). Use break/continue when appropriate. from minor_gripes

Re: Is this PEP-able? fwhile

2013-06-24 Thread Fábio Santos
On 24 Jun 2013 22:29, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Jun 24, 2013 at 2:34 PM, Fábio Santos fabiosantos...@gmail.com wrote: 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

Re: Is this PEP-able? fwhile

2013-06-24 Thread Ian Kelly
On Mon, Jun 24, 2013 at 4:35 PM, Chris Angelico ros...@gmail.com wrote: On Tue, Jun 25, 2013 at 8:30 AM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement it

Re: Is this PEP-able? fwhile

2013-06-24 Thread MRAB
On 24/06/2013 23:35, Chris Angelico wrote: On Tue, Jun 25, 2013 at 8:30 AM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement it (the 'else:' clause). Use

Re: Is this PEP-able? fwhile

2013-06-24 Thread Fábio Santos
On 25 Jun 2013 00:04, MRAB pyt...@mrabarnett.plus.com wrote: On 24/06/2013 23:35, Chris Angelico wrote: On Tue, Jun 25, 2013 at 8:30 AM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has

Re: Is this PEP-able? fwhile

2013-06-24 Thread Mark Lawrence
On 24/06/2013 23:30, Tim Chase wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement it (the 'else:' clause). Use break/continue when appropriate. from minor_gripes import

Re: Is this PEP-able? fwhile

2013-06-24 Thread Tim Chase
On 2013-06-24 23:39, Fábio Santos wrote: On 24 Jun 2013 23:35, Tim Chase wrote: On 2013-06-25 07:38, Chris Angelico wrote: Python has no issues with breaking out of loops, and even has syntax specifically to complement it (the 'else:' clause). Use break/continue when appropriate.

Re: Is this PEP-able? fwhile

2013-06-24 Thread Chris Angelico
On Tue, Jun 25, 2013 at 8:43 AM, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Jun 24, 2013 at 4:41 PM, Fábio Santos fabiosantos...@gmail.com wrote: On 24 Jun 2013 22:29, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Jun 24, 2013 at 2:34 PM, Fábio Santos fabiosantos...@gmail.com wrote:

Re: Is this PEP-able? fwhile

2013-06-24 Thread Fábio Santos
On 25 Jun 2013 00:06, Fábio Santos fabiosantos...@gmail.com wrote: I like how discussions on this list tend to go off topic ;) And now I'm off topic myself :( -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this PEP-able? fwhile

2013-06-24 Thread alex23
On 25/06/2013 6:12 AM, Ian Kelly wrote: On Mon, Jun 24, 2013 at 1:52 PM, jim...@aol.com wrote: Syntax: fwhile X in ListY and conditionZ: fwhile would act much like 'for', but would stop if the condition after the 'and' is no longer True. I would advocate using the break myself. Another

Re: Is this PEP-able? fwhile

2013-06-24 Thread Fábio Santos
On 25 Jun 2013 00:31, alex23 wuwe...@gmail.com wrote: On 25/06/2013 6:12 AM, Ian Kelly wrote: On Mon, Jun 24, 2013 at 1:52 PM, jim...@aol.com wrote: Syntax: fwhile X in ListY and conditionZ: fwhile would act much like 'for', but would stop if the condition after the 'and' is no longer

Re: Is this PEP-able? fwhile

2013-06-24 Thread alex23
On 25/06/2013 9:35 AM, Fábio Santos wrote: I'd probably just go with a generator expression to feed the for loop: for X in (i for i in ListY if conditionZ): That is nice but it's not lazy. If the condition or the iterables took too long to compute, it would be

Re: Is this PEP-able? fwhile

2013-06-24 Thread Fábio Santos
On 25 Jun 2013 01:08, alex23 wuwe...@gmail.com wrote: On 25/06/2013 9:35 AM, Fábio Santos wrote: I'd probably just go with a generator expression to feed the for loop: for X in (i for i in ListY if conditionZ): That is nice but it's not lazy. If the condition or

Re: Is this PEP-able? fwhile

2013-06-24 Thread wu wei
On Tue, Jun 25, 2013 at 10:19 AM, Fábio Santos fabiosantos...@gmail.com wrote: for X in (i for i in open('largefile') if is_part_of_header(i)): The above code would be wasting time on IO and processing. It would load another line and calculate the condition for every line of the large file

Re: Is this PEP-able? fwhile

2013-06-24 Thread rusi
On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote: On Tue, Jun 25, 2013 at 5:52 AM, wrote: (NOTE: Many people are being taught to avoid 'break' and 'continue' at all costs... Why? Why on earth should break/continue be avoided? Because breaks and continues are just

Re: Is this PEP-able? fwhile

2013-06-24 Thread Chris Angelico
On Tue, Jun 25, 2013 at 12:01 PM, rusi rustompm...@gmail.com wrote: On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote: On Tue, Jun 25, 2013 at 5:52 AM, wrote: (NOTE: Many people are being taught to avoid 'break' and 'continue' at all costs... Why? Why on earth should

Re: Is this PEP-able? fwhile

2013-06-24 Thread Benjamin Kaplan
On Mon, Jun 24, 2013 at 8:54 PM, Chris Angelico ros...@gmail.com wrote: On Tue, Jun 25, 2013 at 12:01 PM, rusi rustompm...@gmail.com wrote: On Tuesday, June 25, 2013 3:08:57 AM UTC+5:30, Chris Angelico wrote: On Tue, Jun 25, 2013 at 5:52 AM, wrote: (NOTE: Many people are being taught to

Re: Is this PEP-able? fwhile

2013-06-24 Thread Ian Kelly
On Mon, Jun 24, 2013 at 6:41 PM, wu wei wuwe...@gmail.com wrote: It's still possible by raising a StopIteration within the condition function: def is_part_of_header(x): if header_condition: return True else: raise StopIteration Which is