lua-users home
lua-l archive

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


On Sat, Mar 24, 2018 at 1:46 PM, Petri Häkkinen wrote:

> Will concatenation operator be available out-of-the-box?
> [1, nil] .. [nil, 4]  --> [1, nil, nil, 4]

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 can't imagine possible definition of concatenation for dictionaries.
What should be the result of {a=1, b=2}..{a=3, c=4} ?
But for strong arrays, concatenation is a very natural operation.

 
> [[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

Lua string literal syntax has great and very useful ability to create unlimited nesting without escaping:
[[a]]
[=[ b [[a]] b ]=]
[==[ c [=[ b [[a]] b ]=] c ]==]
...
Three-quote syntax doesn't have this feature

But maybe it would be better to deprecate [[ string literal syntax.
Only [=[  [==[  [===[ ... should work for strings.
Otherwise a lot of people would stumble upon matrix-like syntax problem
m = [[c,-s],[s,c]]