[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua, LuaJIT2 and differences with the length operator
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 5 Jan 2011 10:02:42 -0200
> I would rather prefer:
>
> if type(k) == 'number' and math.floor(k) == k then
> if 1 <= k and k <= n then
> i = i + 1
> else
> return false
> end
> end
>
> This way, table's hash part as well as numeric keys with fractional
> part like 3.33 (which belong to hash part) are excluded from testing.
This is a matter of taste. You may also move the '1 <= k' test to
the outer if, to allow negative indices which also do not interfere
with lists. I particularly do not see much use for such indices (both
negative and fractional), and so it seems simpler to assume that all
numeric indices are in the list.
-- Roberto
- References:
- Re: Lua, LuaJIT2 and differences with the length operator, Leo Razoumov
- Re: Lua, LuaJIT2 and differences with the length operator, Dirk Laurie
- Re: Lua, LuaJIT2 and differences with the length operator, Leo Razoumov
- Re: Lua, LuaJIT2 and differences with the length operator, Roberto Ierusalimschy
- Re: Lua, LuaJIT2 and differences with the length operator, Norbert Kiesel
- Re: Lua, LuaJIT2 and differences with the length operator, Leo Razoumov