lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> On 3/6/10, Roberto Ierusalimschy <> wrote:
> >> If s:sub(5,4) is valid then s:sub(1,0) should be valid too.
> >
> > Sure. s:sub(1,n) is the prefix of 's' with length 'n', so zero must be
> > a valid index to allow the empty prefix. zero is not negative, so it
> > counts from the beginning.
> >
> > -- Roberto
> >
> It's just that since s:sub(2,n) doesn't mean "the substring of 's'
> with length 'n' starting at the second position of 's'", it just feels
> that your point is a happy coincidence rather than a particular case
> of a rule.

At any position i, you need the index (i - 1) to get the empty string.
For i > 1 this is not a problem, but for i==1 you need the index 0.

> I feel like I managed to misuse the "principle of [Roberto's] least
> surprise" and break list etiquette.


-- Roberto