lua-users home
lua-l archive

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


On 4/17/12, Coda Highland <chighland@gmail.com> wrote:
> On Tue, Apr 17, 2012 at 3:12 PM, joao lobato <btnfdp.lobato@gmail.com>
> wrote:
>> On 4/17/12, Coda Highland <chighland@gmail.com> wrote:
>>> Okay, yeah, then the only way to verify issequence is to either (1)
>>> get the real size of the array part (which isn't exposed AFAIK) or (2)
>>> iterate over pairs(t).
>>>
>>> /s/ Adam
>>>
>>>
>>
>> A sequence can have all the key-value pairs in the array-part, all in
>> the hash-part or every case in between.
>>
>> Those two concepts are orthogonal.
>>
>
> I meant to imply that (1) would be something implemented inside the
> interpreter because that behavior isn't defined in the spec. (Indeed,
> the spec doesn't require that anything is implemented array-like as
> long as Lua scripts can treat it as a sequence.) I realized a while
> after I sent the message that I didn't make this clear.
>
> /s/ Adam
>
>

I voiced before my opinion that # could just as well be the number of
elements in the (hash-)table. That way,

    seq = {1,2,3,4,5}
    #seq --> 5

#seq would still be the lenght of a sequence or the number of elements
in a set and would be a O(1) operation. Of course one would lose the
ability to use the array-side and the hash-side of the same table at
the same time. That is actually quite practical and trademark Lua.

Petite Abeille is right. It is best to simply master the #op as it stands.