[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string:sub
- From: spir <denis.spir@...>
- Date: Mon, 8 Mar 2010 18:46:31 +0100
On Mon, 8 Mar 2010 13:21:32 -0300
Roberto Ierusalimschy <roberto@inf.puc-rio.br> 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].
Denis
--
________________________________
la vita e estrany
spir.wikidot.com
- References:
- Re: string:sub, David Burgess
- Re: string:sub, Erik Lindroos
- Re: string:sub, David Burgess
- Re: string:sub, Enrico Colombini
- Re: string:sub, spir
- Re: string:sub, Scott Vokes
- Re: string:sub, joao lobato
- Re: string:sub, Shmuel Zeigerman
- Re: string:sub, Roberto Ierusalimschy
- Re: string:sub, joao lobato
- Re: string:sub, Roberto Ierusalimschy