lua-users home
lua-l archive

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


2015-06-04 15:46 GMT+02:00 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>> In the light of this fact, is there a good reason why the definition
>> of a sequence
>> says "the set of its positive numerical keys is equal to {1..n} for some
>> non-negative integer n" instead of "the set of its positive integer-valued keys
>> is equal to {1..n} for some non-negative integer n"?
>
> Is there a good reason why it should change?

It reflects a pre-5.3 implementation of integers as no different
from any other number. I.e one needs to know the history of
Lua in order to understand why the definition says "numerical"
and not "integer".

Imagine that the concept of "sequence" only came in with Lua 5.3,
when integers are already distinguished and are preferred over
floats of equal value as table keys. Surely the definition would
in that case have been formulated in terms of integes.

> Do you really think it is a good idea to allow fractional keys in between
> the members of a sequence?

I don't think of such keys as specifically numbers, merely as values that
cannot possibly be an index in a sequence, and are therefore not acted
on by the table library.

There is a conceptual problem in saying that fractional keys invalidate
the built-in length function, when (a) they don't need to and (b) in actual
fact do not.