[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.2.0 (beta-rc2) now available
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Wed, 22 Jun 2011 16:53:36 +0200
On 22/06/2011 8.50, David Kastrup wrote:
The last sentence confused me. Did you mean "inside of repeat..until" or
"inside while..do..end" ? "do .. while" doesn't exist in Lua. Or are you
hinting at another language usage?
Lorenzo Donati<email@example.com> writes:
I was just thinking of it right now. I'm not a fan of continue, but I
find it really useful sometimes.
Now that the goto machinery is in place, wouldn't a "continue" keyword
be useful and easily introduced? If I remember well, Lua authors
weren't contrary to it in principle, but because of the
incompatibilities with "until".
Now this seems to work:
::continue:: -- hidden label if continue were introduced
until word == nil
I mentioned this before: the purpose of "continue" is a short-circuit of
a loop before its regular completion. A while-loop _starts_ with the
check of the loop condition as a prerequisite to its regular execution.
A repeat-loop _finishes_ with the check of the loop condition as a
_consequence_ of its regular execution.
For that reason, you want "continue"-like behavior to resume a
repeat-until loop _at_ _the_ _top_ of the loop body, not at the point
where the condition is checked, since the condition is a _product_ and
not a prerequisite of the regular execution, and continue short-circuits
the regular execution.
If you claim possibility for confusion: show me real existing code
(rather than theoretic speculation) using "continue" inside of "do
Anyway I never claimed any possibility for confusion. Please reread my
post (maybe I wasn't clear about it).
As I said, I think I read in an old message by Roberto or Luiz (in an
old of those endless threads about the beauty of continue) that Lua team
wasn't in principle contrary to the introduction of continue as a
counterpart of break, but the problem was that it was too tricky to get
it right with the current (5.1.4) semantics of repeat-until because of
the possibility of bypassing the scope of a local declared after the
continue (*IIRC* - please feel free to correct me if I'm wrong).
So the example above wasn't intended as a smart or cool way to show how
continue could/should be used, but a way to show that, with the proposed
5.2 goto, it could be feasible to introduce continue just as syntactic
sugar for something semantically well defined (in 5.2 beta rc2).
As I stated above, I'm not a fan of continue, in the sense that I don't
think it would cure all the pain in the world :-), nor that I need it at
all costs because it is at the heart of my programming style.
Nonetheless I find it useful sometimes (discount the example above,
please), since in some cases it increases readability (the last time I
wished I had continue at hand, IIRC, was with and endless loop in which
I wanted to take decisions step by step, skipping the loop or breaking
out of it according to some path in the decision process. And, yes, I
know in 99% of cases you can do without continue and be happy anyway. :-)