lua-users home
lua-l archive

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


Sean:

On Fri, 29 Jul 2022 at 04:10, Sean Conner <sean@conman.org> wrote:
>   If I'm doing this, then I would restructure the code to be:
>         -- existing code
>         local function foo()
>           for ...
>             for ...
>               for ...
>                 if somecondition then
>                   return
>                 end
>               end
>             end
>           end
>         end
>
>         foo()

That's a nice usage of local functions....

>   I would do the same to make up for the lack of continue:
>
>         local function foo()
>           while somecondition do
>             ...
>             if somecondition then
>               return foo() -- my "continue" is here
>             end
>             ..
>           end
>         end
>         foo()

... and tail calls ( I use that a lot, but mainly as
structured-uber-gotos, to implement flow-diagram like things ). Color
me impressed, I'm too used to other languages to think of it, but I'm
gonna start calling it "the Connerian transform" and I know a couple
places where it would fit in my code.

>   Remember, Lua can have nested functions.

Although I routinely use them, with their upvalue capturing ability,
as callbacks I have never thought of that, local functions can treat
locals as a kind of "globals for this one invocation". I assume it is
because when I do that refactoring in, say, C++, I have to pass in-out
all the local values and normally I only have needs for long
breaks/continues/gotos in functions with tons of state. Last one looks
Lispy.

Francisco Olarte.