Re:Lua, a Misunderstood Language (2021)
by bawolff on Thursday September 29, 2022 @01:31PM
(#33024244)
All these problems could be solved by just having ++ and += not return a value, which gets rid of all the confusing cases but keeps the useful cases.
Re:Lua, a Misunderstood Language (2021)
by UncleEntity on Friday September 30, 2022 @10:15AM
(#33035123)
++ is useful to switch over the items of a string:
switch (x++) {
case ‘+’:
if (x == ‘+’) {
op = OP_INC;
x++;
} else if (x == ‘=‘) {
op = OP_ADDEQ;
x++;
} else {
op = OP_ADD;
}
break;
…
}
Re:Lua, a Misunderstood Language (2021)
by wruza on Thursday September 29, 2022 @02:37PM
(#33025197)
It may have a confusing behavior, not interpretation. += may mean “evaluate lvalue, add a value to it as usual and set it back”. If you end up getting confused by:
t.x = t.x + v
Then it is a question to t’s metatable designer either way.
Re:Lua, a Misunderstood Language (2021)
by neutrono on Thursday September 29, 2022 @01:27PM
(#33024183)
isn't
y = x + x++;
undefined behavior in C, because of a lack of a sequence point?
If that's true, then it makes sense for no C programmer to know what happens..
I think to fix it you would have to go like:
y = x;
y = y + x++;
I think that would work..
Re:Lua, a Misunderstood Language (2021)
by edflsafoiewq on Thursday September 29, 2022 @12:39PM
(#33023208)
What's confusing about it?
The ++ increment operator is even worse, because it leads to statements within statements. Even an experienced C programmer might have trouble understanding what happens when I write `y = x + x++;`. Lua's grammar achieves a simple parse with no statement delimiters because it enforces a distinction between expressions and statements.