lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

GrayFace <> writes:

> On 23.01.2011 17:35, David Kastrup wrote:
>> I seem to remember that this was basically considered a scope problem
>> since "continue" in a repeat-until, when implemented C-like, was
>> supposed to reevaluate the loop condition, and the loop condition could
>> refer to local variables introduced after the call of continue.
>> My take on this had been that the C behavior is undesirable anyway and
>> that continue in a repeat-until loop should reiterate _straight_ from
>> the top of the loop without checking the _finishing_ loop condition.
>> While not "C-like", this would be much more useful, as well as rendering
>> the scoping problem irrelevant.
> 'Continue' checks conditions of all other loops, so it would be very
> very strange if it's different for repeat..until.

Not at all.  It would reenter the loop at the top.  Since you usually
use "continue" when the proper completion of the loop is foregone, and
since in repeat-until the loop condition is evaluated _after_ the
completion of the loop, there is really no point except some sense of
compatibility or whatever else to jump to the evaluation of the loop:
the perceived problem in the implementation was "what do we do if the
variables of the loop condition are not yet declared", and that is just
a subset of "the loop condition is not even established".

> Not to mention all other languages.

It has never been a goal for Lua to emulate misfeatures.

> As I remember reading in one of such threads, 'continue' patch already
> issues an error if 'continue' may skip declaration of a variable
> that's used in 'until' condition.

Again, I don't consider it sensible to work around one particularly
obvious byproduct of a misfeature.

> My memory may be failing me about the patch, but I think this behavior
> is *the* solution and the whole continue-repeat clash is a non-issue.

Could you give an example of a repeat-until construct where continue
jumping to the evaluation of the loop condition would be a useful thing
to have?

Note that the awkward jump to the loop condition check is not required
for orthogonality: "reenter at the top" is a perfectly consistent
concept.  It is merely required for C compatibility.

David Kastrup