lua-users home
lua-l archive

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


> On 29 Mar 2018, at 7.49, Paul K <paul@zerobrane.com> wrote:
> 
> I like the idea, the implementation, and the result, but am a bit
> uneasy about the new array syntax.

Thanks Paul!

I think arrays deserve a custom syntax for the following reasons:

+ Arrays are really common (My guess would be 50-50 split between arrays and dictionary type data in existing code)

+ newarray(newarray(1,2), newarray(3,4), newarray(5,6)) is not nearly as nice as:
  [[1,2], [3,4], [5,6]]

  (Yeah, I know. Lua raw strings [[...]] have conflicting syntax, but perhaps the syntax for raw strings could be changed as discussed earlier in this thread. Stuff like  [===[ … ]===] being klunky is alone a good reason to consider improving the syntax.)

+ Having full VM support for array constructors is much faster than calling functions (or whatever) to do the conversion from tables or var args to arrays.

+ The semantics of tables and arrays are different so [...] syntax improves the self documenting aspect of code.

---

I guess it would be possible to add arrays without a proper syntax, but would it be "first class" support then?

In my opinion, if arrays would be added to Lua, they would be widely useful and used in a lot of new code, so a full treatment to make them nice and easy to use would be an appropriate thing to do.

Petri