lua-users home
lua-l archive

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


On Jan 12, 2010, at 12:56 AM, steve donovan wrote:
> ... See http://batbytes.com/luafaq/#T1.26
> 
> Basically, repeat..until semantics have to change before continue can
> appear. Personally, I'd prefer the second.


I've been reading this mailing list for quite a while now, and I've
always been puzzled by the apparent consensus, documented in the FAQ,
that continue is somehow incompatible with repeat ... until.  The common
example given is:

  repeat
    if cond then continue end
    local t = 1
    ...
  until t == 0

Sure, that code looks broken, but where is the semantic conflict?

Perhaps the concern is that 't' will be in some heretofore undefined
state, in scope but undefined (not even nil).  But that would be the
case only if the language definition chose to make that the case.  There
is a simple, obvious alternative definition: variables default to nil on
entry to the block.

In fact, I thought this was already the way Lua was defined, but after a
close reading of section 2.4.7 ("Local declarations") I find an
assumption that variables will not enter scope without control flow
passing through an initial assignment.  The wording could easily be
tweaked to remove the assumption (which seems out of place anyway).

The combination of "continue" and "until" does introduce the case where
initial assignments may be skipped, and thereby it presents an
implementation challenge -- ensuring proper initialization in the above
case without adding overhead in other cases.

But there is no semantic "breakage".