lua-users home
lua-l archive

Re: Infinity as index

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


2014年04月23日 11:53 GMT+02:00 Lukas Prokop <admin@lukas-prokop.at>:
> Now my point is that we can use this as indices. My intuition tells me the
> following:
>
> -nan - behaves like a nil as index or throws error (number expected)
> inf - behaves like the end of a sequence as index
> -inf - behaves like the beginning of a sequence as index
>From the manual:
> The type table implements associative arrays, that is, arrays that can be
> indexed not only with numbers, but with any Lua value except nil and NaN.
This is pretty definite. tbl[inf] and tbl[-inf] are allowed. They are definitely
allowed as lvalues, and the following (highly inefficient) algorithm will
find them (it will not find nan).
function index(tbl,j) for k,v in pairs(tbl) if k==j then return v end end end
IMHO it is a bug that tbl[inf] and tbl[-inf] does not work. Too late
for Lua 5.1,
but this could still make the final Lua 5.2 release.

AltStyle によって変換されたページ (->オリジナル) /