lua-users home
lua-l archive

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


It would be simpler to have the very basic syntax  "t[] = newElement" instead of  "t[#t+1] = newElement" ... No need to introduce any "@" (ambiguous in your example) or "#+1".

We could also have "t:append(newElement)", but this could conflict with an existing append() method existing as a member "t.append" in "t", or found by an __index access method in its metatable. Instead the "t[]=value" syntax could be bound to an __append(t,value) method settable in the metatable of tables (allowing that method to determine which new index key to assign, if it should be different from #t+1 by default).




Le jeu. 15 août 2019 à 10:00, Oliver <oschmidt-mailinglists@gmx.de> a écrit :
On 13.08.19 06:45, Sean Conner wrote:
>   Well, another pain point is
>       veryLongNmae[complexLValue] = veryLongName[complexLValue] + 1

a similar and common use case is appending an element to an array: it's also
painful to write:

        complexLValue[#complexLValue + 1] = newElement;

One can circumvent this by having a append function:

        append(complexLValue, newElement);

but this makes the assignment not as visible as the first approach does.

A solution for current official lua with explicit assignment:

        local list = complexLValue; list[#list + 1] = newElement;

Can this be rewritten using the imaginary @ operator?

        complexLValue[#@ + 1] = newElement;

Now the @ would be on the left side of the assignment, this looks weird.

-- Oliver