lua-users home
lua-l archive

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


Hi,

Unfortunately, this is not compatible with the semantics of "continue".

repeat
 local l = io.read"*l" or "quit"
 if l:match"^#" then continue end
 local g, rest = l:match"(%S+)%s*(.*)"
 local done = handle[g](g, words(rest))
until done

Sorry, I was away and missed this nice thread. I feel guilty because I
bothered Roberto some time ago with this change, so now it is my dutty
to defend it. :)

Think first about why this could be a good idea. In the old style, you
would need to declare "done" outside of the "repeat" loop in order to
be able to read its value in the until expression.

First, this makes it less obvious that "done" is in fact only used
inside your repeat block. Second, you can't use a on-liner anymore.

Now, ignoring the fact that we do *not* have a continue statement in
Lua, at least not yet, I don't understand what is it that broke which
worked before.

  local done
  repeat
   local l = io.read"*l" or "quit"
   if l:match"^#" then continue end
   local g, rest = l:match"(%S+)%s*(.*)"
   done = handle[g](g, words(rest))
  until done

If you assume the old scoping rule and use the above declaration, you
will still skip assignment to "done". Will Lua detect such a problem?
Does this loop not work the same as the other? I might be just tired.

[]s,
Diego.