[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: string:sub
- From: spir <denis.spir@...>
- Date: Sat, 6 Mar 2010 17:28:53 +0100
On Sat, 06 Mar 2010 11:29:25 +1100
David Burgess <firstname.lastname@example.org> wrote:
> It seems to me that negative values of string.sub() are inconsistent
> with not only the first parameter but also with string.find().
> 5 6
> I am boldly suggesting that the second parameter with negative indices
> behave the same as the first.
That's what id does. (Unlike eg in python.) What do you mean?
> I guess this implies that the value 0 for
> the second parameter would return the length of the string.
So you wish to break the symetry between positive and negative indices?
This may make sense for half-open interval, where in fact s.sub(i,j) == s[i,j[.
> Maybe I have used too many similar functions in other languages but -1
> meaning the last character seems intuitive to me.
-1 precisely points to the last character. s.sub(-1) == s.sub(#s)
So, what's wrong? (These points precisely are Lua features I'm very happy with :-)
la vita e estrany