lua-users home
lua-l archive

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


On Mon, Jun 1, 2015 at 6:14 PM, Andrew Starks <andrew.starks@trms.com> wrote:
>
>
> On Monday, June 1, 2015, Brigham Toskin <brighamtoskin@gmail.com> wrote:
>>
>> On Mon, Jun 1, 2015 at 3:31 PM, Coda Highland <chighland@gmail.com> wrote:
>>>
>>> On Mon, Jun 1, 2015 at 3:27 PM, Brigham Toskin <brighamtoskin@gmail.com>
>>> wrote:
>>> > On Mon, Jun 1, 2015 at 3:07 PM, Roberto Ierusalimschy
>>> > <roberto@inf.puc-rio.br> wrote:
>>> >> Another reason not to do so is that it makes '#' mostly useless for
>>> >> sequences (which are the only reason for its existence).
>>> >
>>> >
>>> > Oh, I don't know that's necessarily true. In the case where t is a
>>> > sequence
>>> > (with no non-numeric keys), then #t == numentries(t), sure. But they
>>> > are
>>> > answering fundamentally different questions. It's kinda like saying
>>> > that
>>> > pairs() is a bad idea because it makes ipairs() redundant for
>>> > sequences.
>>>
>>> Historical note: ipairs() nearly got removed (in favor of "for k in 1,
>>> #t") so this might not be the most useful argument. ;)
>>
>>
>> I think I've actually written that exact line of code a few times ;)
>>
>> The real point I suppose is that "it makes something else not useful" is
>> probably only more reason to do it, not an argument against.
>>
>> --
>> Brigham Toskin
>
>
> This is not true. I do not want # to count string keys; only integers from
> 1..n where the values are not nil. So, the current behavior is all that I
> want. I'm not against anything here, but I've never needed to know that
> total number of non-nils.
>
> I have wanted to loop through a table and have the numeric keys in order and
> the string keys in any order they choose.
>
> I care about ordinality and not always sequences. There are many times that
> I wish that ipairs would go through all integer keys, in order. I've never
> needed all numbers (float too) to behave that way, but if it did, it would
> be fine. One could argue for that world and then checking for sequences
> would be uber trivial. But that would make writing numeric keys somewhat
> special and would break code.
>
> As is, I do tricks like table of tables with [1] containing the index and
> it's fine.
>
> -Andrew
>

That's why a modification of # isn't under discussion; a new function is.

/s/ Adam