[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 'table' as fallback for tables
- From: Coda Highland <chighland@...>
- Date: Mon, 27 Jun 2016 10:43:13 -0700
On Mon, Jun 27, 2016 at 10:40 AM, Coda Highland <chighland@gmail.com> wrote:
> On Mon, Jun 27, 2016 at 10:29 AM, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
>>> Bingo! I'd say an `n` key with an integer value greater than or
>>> equal to 0, but let's not nitpick. I also think this would have been
>>> a viable alternative to the sequence concept we now have, because it
>>> has some useful properties:
>>>
>>> * [...]
>>
>> Something that seems to be missing in this discussion is constructors:
>>
>> l = {1, 2, 3, 4, 5}
>> print(#l) --> ? (no 'l.n'...)
>>
>> -- Roberto
>>
>
> I think this has been mentioned before, but my personal opinion is
> that table.pack is effectively the "array constructor".
>
> l = table.pack(1, 2, 3, 4, 5)
> print(#l) --> 5, obviously
> print(l.n) --> also 5
>
> /s/ Adam
Upon further reflection this has a noteworthy disadvantage of being
considerably worse performance than a table literal, since it can't be
efficiently handled at compile time.
Fixing that would... probably require new syntax. So maybe I'm wrong
and this isn't a good way of going about it.
/s/ Adam