
Greg Ewing wrote:
Jan Kaliszewski wrote:
while foo(x) and bar() where: foo = SOMETHING def bar(): SOMETHING ELSE do: THE LOOP BODY
That's kind of clever, although it does require modifying the while-loop syntax, and if you're doing that, there's not a lot of gain over introducing a dedicated loop-and-a-half syntax.
Also, once we're allowed 'where' clauses on while statements, people are going to want them on other kinds of statements as well:
if a == b where: a = foo() b = blarg() then: ...
class Ham(Spam) where: class Spam: ... is: ...
def f(x = default) where: default = whatever as: ...
try: ... except eels where: eels = something_bad() do: ...
Where do we stop?
while foo(x) and bar(): where: foo = SOMETHING def bar(): SOMETHING ELSE THE LOOP BODY
I think I liked the first version better. There's something jarring about the unindent half way through without any keyword to mark the boundary. Also the bare 'where' relating to the previous line suggests some weird grammatical gymnastics going on.
"do" might be a sufficiently generic word to cover all the cases. while ... where: ... do: ... if a == b where: ... do: ... etc.