groff
[Top][All Lists]
Advanced

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

Re: [Groff] Re: .substring bug - indicies don't work as documented(?)


From: Ralph Corderoy
Subject: Re: [Groff] Re: .substring bug - indicies don't work as documented(?)
Date: Sun, 28 Oct 2001 14:18:01 +0000

Hi Bernd,

> Python starts the position counting with 0, like C, while groff
> starts at 1.  So Python positional calculation is fundamentally
> different and cannot be taken over.

Sure it can.  Besides, Icon's is similar to Python's yet starts at one.

    http://www.nmt.edu/tcc/help/lang/icon/positions.html
    http://www.nmt.edu/tcc/help/lang/icon/substring.html

> 0 is meant to be the end of the string, i.e. the position _behind_
> the last character, while the number of the last character denotes
> the position on the last character.

It seems very confusing to mix positions and indexes.  Indexes refer to
a character, positions to the places between characters (and the ends
of the strings).

> > Yes, it could be.  I guess it depends on whether reversing the
> > string or having the indices in the wrong order is more common.
> > This way avoids the `if (i1 > i2) swap(i1, i2)'.  Another option
> > would be Python's way of returning an empty string which is again
> > sometimes what you want.
> 
> I agree to all possibilities, except the swapping.

Once the definition of n1 and n2 are positions, rather than indexes,
then .substring is defined as returning the string between those two
positions.  The order of the positions is therefore irrelevant and it
works either way around.

Cheers,


Ralph.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]