do...until wisdom needed...
Alex Martelli
aleaxit at yahoo.com
Mon Apr 16 16:01:11 EDT 2001
"Ken Peek" <Peek at LVCM.comNOSPAM> wrote in message
news:tdlva0ci1s13e7 at corp.supernews.com...
> Please see my answer to Andrew Dalke in a sub-thread above...
I've seen it, and in no way does it address my response. I repeat
the meaningful part:
"""
It would be best to have one general guarded-loop construct implementing
the Knuthian "N and 1/2 times" loop, rather than two different constructs
each implementing only a special case of it. Exact syntax sugar could be
endlessly (and fruitlessly) debated, but the general idea might be:
loop:
[suite 1]
while [condition]:
[suite 2]
The 'loop' keyword and associated [suite 1] would be optional, so that just
by omitting this clause one would get back to today's while-loop.
"""
If you want to tweak the syntax sugar by having, e.g., 'do:' instead of
'loop:', this strikes me as crazy (why imply something is just "done",
which does NOT communicate repetition, when "loop" DOES?!), but,
hey, it's your fune^H^H^H^H language, go right ahead. Similarly
for other potential atrocities such as introducing 'until floop' as a
synonym or replacement of 'while not floop'.
It IS better to have one general tool than two special-purpose tools
(which, together, don't equal the expressivity of the former!), if and
only if the general tool doesn't make you pay a price in terms of
_simplicity_. The Knuthian loop/while is utterly simple. You may
choose to make it a bit richer still without adding _complexity_ (nor
real complication) by having more optional clauses, a la:
loop [while condition1] [:
[suite1]]
{while conditionN[:
suiteN]
}
where metasyntax [...] indicates an optional part (0 or 1 times)
and { ... } indicates repeatability (0 to N times for any N). This
gives "more than one way to do it" for typical constructs such
as while-loops, so it would be inappropriate in Pythonic terms,
but the language you're designing is not Python. Alternatively,
you might choose to make the 'loop' keyword NON-optional:
have it introduce ALL loops and gain regularity. Classic loops
would then be:
loop while condition:
suite
for a normal while loop (test-at-start, 0-or-more-times),
loop:
suite
while condition
for a test-at-end (1-or-more-times) loop. Knuthian
N-and-1/2-times (test-in-the-middle) would be:
loop:
suite1
while condition:
suite2
and you could have more than one 'while' for the same loop
for non-classic variants (you could choose to prohibit them,
mandating "exactly one while clause per loop", if you wish).
Alex
More information about the Python-list
mailing list