[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Nitpicking about string.sub argument validity check
- From: Albert Chan <albertmcchan@...>
- Date: Fri, 31 Aug 2018 18:09:06 -0400
On Aug 31, 2018, at 5:03 PM, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:
> Hi!
>
> It is reasonable to warn user about "string.sub" usage mistakes such as
> str:sub(1, 3.14)
> that's why in Lua 5.3 string.sub might raise "number has no integer representation" error.
>
> But it appears that math.huge as argument also raises this error.
> IMO, the following use cases should be considered as being valid:
> string.sub("abc", 2, math.huge)
> string.sub("abc", -math.huge, -2)
> Yes, I know we could use -1 and 1 values respectively to get the same results,
> but infinite values are suitable for the semantic of the function.
How to tell if 3.14 were a mistake, and math.huge is not ?
I just felt uneasy using infinity as end-point ...
Especially bad if the infinity value is hidden behind a variable.
What is gain by not using 1 for first location, -1 for last ?