lua-users home
lua-l archive

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


On Tue, May 7, 2019 at 10:00 PM Philippe Verdy <verdy_p@wanadoo.fr> wrote:
abs(n) is as much arbitrary as the number of digits, i.e. roughly log10(abs(n) for integers...

Agreed; log10(abs(n)) is a halfway reasonable but still arbitrary choice that still carries the notion of "size".
 
Also I agree that length == 0 is valid to represent an empty set, but it's still not a valid Lua sequence number.

I'm not sure what you mean by a "sequence number". Do you mean an index? Well of course it isn't. There are no valid indexes into an empty sequence, because it's empty. Why would you EXPECT 0 to be valid? Why does that even matter for anything?
 
As well "#t" in Lua is not the total number of items in a table, but only the length of one of its extracted sequences.(which are not unique or could be empty if the table has holes for some sequence numbers. Meaning efefctively that "#t" or ipairs(t) is unreliable in Lua for tables, and works only for some of them that are valid sequences. And even if it's a valid sequence, there may still be more items in the table (whose keys are not integers or are integers <= 0 and thus implicitly excluded from sequences).

Yes, we've already clearly established that # is only well-defined for proper sequences, which means that this entire discussion is hypothetical hand-wavy musing.

A table can be an improper sequence, at which point # and ipairs don't necessarily align and # is measuring a very specific thing about tables instead of a generic notion of "size". My hypothetical extension of # to numbers does exactly the same thing: for numbers that unambiguously represent a proper sequence given the appropriate iterator, it returns the value you would expect, while providing a well-defined return value when you're outside of the strict domain.
 
But your initial comment allowed the value 0 in keys of the input table, which was incorrect

No it didn't...? My initial comment said that if 0 is treated as the upper bound of an iteration then it would perform 0 iterations -- it would never try to use 0 as an index.
 
Because it only allows 0 on valid output for the "length" of some unpredicatable sequence (including an empty sequence) extracted from the table,. If #t == 0, it does not mean that table t is empty..

In the Lua style, I have been careful to define the domain of what is well-defined and what is ill-defined, and I have been careful to say exactly what I mean.

I never said #t == 0 means the table is empty. I said it means that the SEQUENCE is empty, and I'm right about that. It means that ipairs(t) will perform 0 iterations. And by symmetry, if we create a range() iterator for numbers, then #0 == 0 means that the sequence represented by the number 0 is empty, and range() will perform 0 iterations. To support this notion I also pointed out that a chars() iterator for strings would also have this property.

/s/ Adam