lua-users home
lua-l archive

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


I share your feelings about the `continue` keyword, but I suspect that the Lua developers would probably disagree since, if you search through the C files in the Lua code base itself, there are only two (!!) uses of the `continue` keyword in the entire code base (lgc.c in version 5.4.5).
David

On Fri, Mar 17, 2023 at 9:18 PM sur-behoffski <sur_behoffski@grouse.com.au> wrote:
I really like C's "continue" keyword, as it lets me identify and handle
special cases at the top of a loop, leaving the coast (and indentation)
clear for meaty logic further down.  (I deliberately abhor deep nesting,
as I believe that the layers of logic wrapping a line of code can make the
line harder to comprehend... this is why I always use 8-column indenting.)

If possible, I'd like to have a continue facility available across all
Lua 5.1 .. 5.4 versions.  This is infeasible, as "continue" may be an
identifier within other scripts.

I use std.normalize (and std.strict) in all my scripts, trying to code
at the 5.1 level, but with semantics identical across the version spread.
Rock "bit32" is another example of trying to normalise across versions.

So, in an ideal world, I'd like to be able to require a new Rock, which
uses a (new?) hook provided by the VM, tied to a
possibly-mostly-compatible version of "continue":  Perhaps "continue__"?

Sadly, I don't know enough about the VM(s) to know if this is feasible,
and, even if it was, I strongly suspect that the Lua team would be loathe
to revisit past versions.

At present, I use deep indentation as a strong hint that the code needs
to be refactored, probably using another function to reset the nesting
level.

Hope this helps,

s-b etc