[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.4-work1 with first class arrays (implementation & benchmarks)
- From: Petri Häkkinen <petrih3@...>
- Date: Sat, 24 Mar 2018 12:46:09 +0200
> On 23 Mar 2018, at 20.59, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:
> Wow! That's strong arrays!
>
> Will concatenation operator be available out-of-the-box?
> [1, nil] .. [nil, 4] --> [1, nil, nil, 4]
Thanks for the interest in this experimental patch!
First of all, I have no plans to further work or maintain this proof of concept fork of Lua. I made it merely so that others could evaluate the feasibility of having an array type in Lua, and also demonstrate how it could be efficiently implemented (without slowing down regular tables).
I don’t have a strong opinion whether arrays would need a concat operator by default, but since they’re not available for tables either and arrays are basically tables with some special semantics for insertion/removal, I’m not sure concat operator would be consistent to have by default.
> How about default arrays' metatable?
> ([1, nil, 3]):sub(-2) --> [nil, 3]
> ([]):append(42, 33, nil):remove(2) --> [42, nil]
I would prefer to have regular functions that work on both tables and arrays. For example table.remove() works on both tables and arrays.
Just a personal preference of mine... I’m not a fan of the object oriented ‘:’ call syntax at all. I think OOP in general is a huge mistake, waste of programmer time and CPU cycles and can easily lead to overengineered code that is hard to understand and maintain.
> How to stop writing [[ when I want to create 2D-array?
> [ [1], 2] -- ok
> [[1], 2] -- syntax error
> [[1],[2]] -- syntactically correct, but not a 2D-array! :-)
Yep, this is a caveat, but as you showed, can be worked around by adding a space between ‘[‘ so not a huge problem.
I wish Lua could have chosen another syntax for multiline strings though. For example
"""this is a
multiline string"""
would have been more logical choice and easier to type, but I understand there are issues with escaping inside the string (mental note to myself: check how other languages handle """ as part of the string).
> Could we sometimes create an array without actually creating an array?
> function f(...)
> local arr = [...]
> -- if the code of this function doesn't modify arr (and doesn't pass arr somewhere else)
> -- then data should be stored on the stack, no array actually should be created
> -- access to arr[k] and #arr should be emulated
> for k = 1, #arr do print(k, arr[k]) end
> end
This is not really related to arrays (tables could benefit from the same optimization). These kind of code generation optimizations would increase the complexity of Lua implementation greatly and are generally not done for simplicity.
Petri