[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Infinity as index
- From: "Lukas Prokop" <admin@...>
- Date: Wed, 23 Apr 2014 15:04:49 +0200 (CEST)
> On Wed, Apr 23, 2014 at 2:26 PM, Dirk Laurie <dirk.laurie@gmail.com>
> wrote:
>> 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.
>
> Just tested with 5.2.2:
>
>> inf = 1/0
>> = inf
> 1.#INF
>> t[inf] = 10
>> = t[inf]
> 10
>
> I'm trying to understand what t[inf] is meant to do with the proposal
> "behaves like the end of a sequence as index". Like t[#t]?
This was not meant to be a proposal. In fact I did not think about tables
at all when starting the discussion. But I'm glad to discuss it and Dirk
Laurie's points regarding tables are interesting.
> a = {}
> a = {42, 43, 44, 45}
> =a[inf]
nil
For general lists I don't think infinity should mean the same like "#a" in
any way.
To me the crucial point is indexing of strings.
> a = "hello world"
> = a:sub(1/0)
hello world
>
Infinity should refer to the end of the string here IMHO. Therefore I expect:
> a = "hello world"
> = a:sub(1/0)
>
best regards,
meisterluk
[0] I would be grateful if someone can give me a pointer how infinity is
handled by the compiler (per private email). I could not understand the
layout of inf in expdesc. If so, I would try to provide a proposal for
this discussion.