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.
>
> I misunderstood your point. You mean indices for the string library,
> not indexing in a table. In that case, indices are converted to integers.
>
> The Lua value must be an integer, or a number or string convertible
> to an integer (see §3.4.3); otherwise, lua_tointegerx returns 0.
>
> Since infinity is not an integer, it is treated as 0.
Okay, thank you. So coming to the root of the problem, I guess there are 2
questions related to the same topic (which are partially answered by the
spec):
1. Shall inf, -inf and -nan be allowed as indices for strings?
2. Shall inf, -inf and -nan be numbers in general?
 [leading to a change in semantics of lua_tointegerx]
Why shall we discuss it? Because this is non-intuitive for me:
 > a = "hello world"
 > inf = 1/0
 > = a:sub(inf)
 hello world
 > = a:find("e", inf)
 2 2
I have to point out that languages like python do not support infinity as
indices as well. Any other pros/cons?
best regards,
meisterluk

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