Thoughts on PEP315

John Roth newsgroups at jhrothjr.com
Mon Sep 22 21:47:05 EDT 2003


"Stephen Horne" <$$$$$$$$$$$$$$$$$@$$$$$$$$$$$$$$$$$$$$.co.uk> wrote in
message news:oalumvopu9afuhno85tbp2erl52rk9hht1 at 4ax.com...
>
> PEP315 (Enhanced while loop) suggests a syntax as follows...
>
>   do:
>     ...
>   while condition:
>     ...

I've snipped the rest of your lengthy analysis because I think
the problem is much deeper, and is essentially insoluble given
the structure of Python.

The difficulty is that there is no clear and obvious way of
distinguishing subordinate groupings from the main grouping.

Consider the if statement:

if something:
    blah blah
elif something_else:
    blither
else:
    bletch

If we look at this, without knowing the syntax of the
if statement, it looks like three primary statements.
There is no a priori way of knowing, from the lexical
structure of the language, that elif and else cannot
occur by themselves, but must be preceeded by
a specific statement. You need the additional layer
of the syntactic relationships.

Consider the same structure in Ruby:

if something
    blah blah
elsif something_else
    blither
else
    bletch
end

The thing that makes all the difference is the "end"
statement which closes the if. The elsif and the else
are clauses within the if statement, and there is no
way of missing that fact even if you don't know the
exact syntax of the if structure.

If we now go back to the loop suggestion,
it becomes rather obvious what needs to be
done:

do:
    bibbity
    bobbity
    boo
    while condition  # note the lack of a colon!

This is at least unambiguous as to what is
going on.

I don't, by the way, think that we need this
particular piece of syntactic sugar, regardless
of the syntax we dress it up in.

John Roth

>
>
> -- 
> Steve Horne
>
> steve at ninereeds dot fsnet dot co dot uk






More information about the Python-list mailing list