[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Next Version of Lua?
- From: Hisham <hisham.hm@...>
- Date: Fri, 19 Jun 2009 12:51:04 -0300
On Thu, Jun 11, 2009 at 11:30 AM, Roberto
>> * Roberto Ierusalimschy:
>> > Any comment about this?
>> > http://lua-users.org/lists/lua-l/2005-09/msg00548.html
>> "until" could have been "break if", and the "repeat ... until exp"
>> could have been "repeat ... break if exp end", where "repeat ... end"
>> is an endless loop.
> It is, and that is the problem. If you have repeat + continue, it
> becomes this:
> repeat ... continue ... break if exp; end
> With this interpretation, the continue goes to the end of the loop,
> bypassing the "break if exp". This is not what most people expect
> from continue.
I confess I've never given too much thought to the exact semantics of
'continue', and have been using it for many years (and missing it in
Lua for a few, by now). Amazingly, I've always read it as "jump back
to the top of the loop", having never realized that it actually "jumps
back to the test" -- and have never been bitten by this error!
(Probably because every time I 'continue' in a repeat loop, I'm doing
it when I expect the loop to, well, continue running, and so my exit
conditions don't trigger anyway.)
So I'm guessing that my personal "expected" behavior for
continue-within-repeat would be Peter Cawley's alternative number 5:
> 5) A "continue" within a repeat ... until construct causes execution
> to jump back to the statement immediately following the "repeat", thus
> skipping the "until" clause entirely.
This would make 'continue' mean "jump to the top", and would be
consistent with 'while' and 'for'. Perhaps, as you said, "this is not
what most people expect from continue", but then again, I'd venture
that 'until' clause already has semantics that most people don't
expect, anyway. (It's just odd to see a variable being used in a lower
indentation level than it is declared.)
So, in short, my two-cents is that, given that repeat-until in Lua
doesn't work like other languages anyway, Cawley's option 5 would give
people continue with semantics that's consistent among looping
constructs and would have no weirdness for 'while' and 'for'.