lua-users home
lua-l archive

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

On Mon, 8 Mar 2010 13:21:32 -0300
Roberto Ierusalimschy <> wrote:

> > 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.

This is a strange point of view, for me. I mean it's fully correct, sure, but when do we need to express an empty (sub)string (or any kind of sequence) using literal indexes?
With variable range borders, string.sub(m,n) evaluates to '' if n < m, right. But this does not mean string.sub(i, i-1) "means" or is the expression of the empty string. "" is the expression of the empty string, {} is the expression of the empty sequence...
OK, it's just words, but I once read an article (a rant, infact ;-) arguing that half-open intervals are better precisely because the empty string is then nicely expressed as [n,n[ instead of [n,n-1].


la vita e estrany