Re: PEP-315 ("do" loop)

From: John Roth (newsgroups_at_jhrothjr.com)
Date: 02/17/04


Date: Tue, 17 Feb 2004 07:15:34 -0500


"Wayne Folta" <wfolta@netmail.to> wrote in message
news:mailman.55.1076984559.31398.python-list@python.org...
Two observations about PEP-315:

1. It's clever, addresses a definite "wart", and is syntactically similar to
try/except. But it's syntax seems like an acquired taste to me.

2. It is a very general construct, which might be what is called for. But I
wonder if most of the time it would be used to accomplish something like:

while 1:
    line = sys.stdin.readline()
    if line == "\n":
        break

In a neater way? How about, instead, creating an "until" loop:

until line == "\n":
    line = sys.stdin.readline()

Would be defined to work exactly like a while loop except the test is not
evaluated the first time through the loop. Wouldn't this be akin to checking
at the end of the loop, while maintaining a more while-ish syntax?

Is this at all useful or is something of the order of PEP-315 the way to go?

[response]

1. I've reindented your examples - they don't indent properly under some
browser.

2. Please use plain text - the reason your message isn't quoted properly is
that you used something else, and my news client breaks the formatting.

Now to the substantive responses.

1. The proposed syntax breaks Python's indentation scheme in a manner that
try-except, for-else, while-else, and if-elif-else do not.

2. What I find more serious is that there are a huge number of ways to go in
"improving" the basic while loop, none of which seem to be a natural
stopping point. Python's philosophy seems to be to find the "sweet spot"
where you gain the most leverage with the minimum amount of mechanism.
Neither PEP-315 nor any of the "improvements" I've seen do that.

John Roth



Relevant Pages

  • Preview chapter about the structured syntax definition of Seed7
    ... I am writing a chapter about the structured syntax definition ... will be used as base to explain the S7SSD. ... that a new statement, the 'loop' statement, should be defined. ... Priority and assoziativity ...
    (comp.compilers)
  • Re: Am I the only one who would love these extentions? - Python 3.0 proposals (long)
    ... Why is it nice enough to make it be a syntax addition, ... to point an image viewer/editor at a chunk of Python code. ... You argue consistancy to other keywords. ... Why is this new loop construct of yours useful enough ...
    (comp.lang.python)
  • Re: How about this syntactic candy?
    ... I can think of that's worse than adding a rarely needed, rarely beneficial syntax is adding one that actually allows one to lie to the compiler in a way that _breaks_ the code. ... But more significantly, IMHO, the reason that syntax has survived so many generations of this family of languages is that it's so commonly useful. ... simple for loop. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: spurious wakeup
    ... It can be wrapped in a macro if you insist on ... > You must remember to repeat this loop at all places of the wait call ... checking of all values of variables which influence the predicate. ... > Templates are the safe syntax for a lot of macros. ...
    (comp.lang.cpp)
  • Re: c++ documentation
    ... >>It doesn't bother me though I wouldn't use it in practice ... >>to declare two or more variables of different types in the loop ... > use the constructor syntax. ... syntax for UDTs than *grotesquely twist* the initialisation syntax ...
    (comp.os.linux.development.apps)