I'm against infinite loops -something religious :), which explains the call for the do loop.
The issue about the parser is over my head, but the thought had occurred to me. Now, it would not affect while loops inside do loops, wouldn't it? Cheers, Hans. -----Original Message----- From: Nick Coghlan [mailto:[EMAIL PROTECTED] Sent: martes, 03 de octubre de 2006 15:51 To: Fuzzyman Cc: Hans Polak; python-dev@python.org Subject: Re: [Python-Dev] PEP 315 - do while Fuzzyman wrote: > Nick Coghlan wrote: >> In my example, the 3 sections (<setup code>, <loop body> and <loop completion >> code> are all optional. A basic do-while loop would look like this: >> >> do: >> <setup code> >> while <condition> >> >> (That is, <setup code> is still repeated each time around the loop - it's >> called that because it is run before the loop evaluated condition is evaluated) >> >> > > +1 > > This looks good. I'm pretty sure it was proposed by someone else a long time ago - I was surprised to find it wasn't mentioned in PEP 315. That said, Guido's observation on PEP 315 from earlier this year holds for me too: "I kind of like it but it doesn't strike me as super important" [1] > The current idiom works fine, but looks unnatural : > > while True: > if <condition>: > break There's the rationale for the PEP in a whole 5 lines counting whitespace ;) > Would a 'while' outside of a 'do' block (but without the colon) then be > a syntax error ? > > 'do:' would just be syntactic sugar for 'while True:' I guess. That's the slight issue I still have with the idea - you could end up with multiple ways of spelling some of the basic loop forms, such as these 3 flavours of infinite loop: do: pass # Is there an implicit 'while True' at the end of the loop body? do: while True while True: pass The other issue I have is that I'm not yet 100% certain it's implementable with Python's parser and grammar. I *think* changing the definition of the while statement from: while_stmt ::= "while" expression ":" suite ["else" ":" suite] to while_stmt ::= "while" expression [":" suite ["else" ":" suite]] And adding a new AST node and a new type of compiler frame block "DO_LOOP" would do the trick (the compilation of a while statement without a trailing colon would then check that it was in a DO_LOOP block and raise an error if not). Cheers, Nick. [1] http://mail.python.org/pipermail/python-dev/2006-February/060711.html -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com