[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Don't split the list, Lua the Lua way: was Time to split the Lua list?
- From: Philippe Verdy <verdy_p@...>
- Date: Sun, 9 Dec 2018 16:42:12 +0100
Well, Lua has "labels" but the "break" statement cannot be used to break several loops (for, repeat, while), even if these loops are labelled, we still cannot simply use "break label_name" (which would not be a goto as it should go just *after* the loop and not just before...
We can use a trick: define a function containing the loops, and returning from the function instead of breaking. But using an extra function does not play well. So we're left using ugly "goto" statements by adding an extra label just after the loop (possibly with a colon to create an empty statement). It should be better/cleaner to label the loop statement itself.
As well the absence of a "switch" statement forces us to use multiple "elseif" clauses causing the same _expression_ to be evaluated multiple times, or to declare a local variable, which should be implicit; but then the local variable persists in scope after the "if...elseif... else... end" block, and if should be desirable to reduce its scope, so we have to use a dummy "do...end" block to enclose the "local" variable declaration and initialization and the "if...end" statement. This does not make the code really cleaner and does not simplify the compilation to optimize these ifs (e.g. using a jump lookup vector) without analysing each _expression_ given in "if..." and all "elseif..." clauses, to find if they test the same value and compare them possibly with "or"/"and" subexpressions. This is much work for the compiler that would be avoided using a simple switch comparing the tested _expression_ with a list of distinct constants (evaluated at compile time)...
On Sat, 1 Dec 2018 13:23:34 -0500
Phil Leblanc <email@example.com> wrote:
> What do you think?
List splitting almost never accomplishes anything good, and often
brings bad things.
I've been gone since 2016 because this list is very prolific and I
didn't have time for it after switching my main language to Python3.
I've come back and noticed something hasn't changed: People keep asking
Lua to become something it isn't. For example, the huge Lua Needs
thread appears to be that somebody needs some sort of scaffolding to do
"composition based OOP" (I don't have the original post).
To me, if there's ever been any language facility supporting
composition, it's the Lua table. And although, at least through Lua
5.3, Lua doesn't have an official, dedicated Object Oriented
Programming syntax. You can accomplish the same things, at least as
easily, using what Lua offers, but it seems like some want Lua to
incorporate riffs from other languages.
I've always appreciated the way you can do almost anything with a Lua
table and closures. A developer needn't concern herself with zillions
of complex data types, each having its own methods or performing
differently on shared methods.
I wish people would just let Lua be Lua, and not suggest changes for
the language. If we wanted Rust or Python or C++, we'd be using them.
To me, the only reason to change the language is if the language cannot
perform a task without the change. Years ago, I asked for one change to
Lua: Inclusion of a "continue" statement for loops. When nobody else
found such a construct necessary, I posted a workaround so, within a
loop, I could have a construct that had the role of "give me the next
line and start again at the loop's top." Nobody could find a better way
to perform that role than my workaround, and several people found my
workaround so obscene that a continue statement was added to the
If there's something that Lua can't do in any reasonable way, perhaps a
change in the language is called for. But if a change is proposed to
provide yet another way to do it, why not just use Perl, where "many
ways to do it" is a fundamental part of the language's purpose?
December 2018 featured book: Rapid Learning for the 21st Century