groff
[Top][All Lists]
Advanced

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

Re: [Groff] changed .substring


From: Bernd Warken
Subject: Re: [Groff] changed .substring
Date: Mon, 8 Jul 2002 09:43:43 +0200
User-agent: Mutt/1.2.5i

On Sun, Jul 07, 2002 at 10:04:25AM +0200, Werner LEMBERG wrote:
> 
> While fixing bugs in .substring I've changed the request to make
> index 0 the first character, and -1 the last.
> 
I think that your implementation is well done and is quite usable.
Unfortunately, it is not yet compatible to other programming languages.

The actual groff implementation has

.ds s abcdefg\"
.substring s 0 3
.tm => \*[s]

=> abcd


Emacs, however, does (from the Xemacs info file):

          (substring "abcdefg" 0 3)
               => "abc"


Python parallels Emacs.


The difference is that groff follows the notion of "including" for the
.substring arguments, while the other languages use the notion of
"before".

I prefer Werner's implementation from a user's point of view.  But then
we must be conscious about the fact that .substring is not compatible
to other languages.  

_______________________

If we agree on discarding this kind of compatibility, I have another
proposal for improvement.  The actual groff implementation allows to
specify the rest of the string by having `-1' as a third argument, e.g.

.ds s abcdefg\"
.substring s 2 -1
.tm => \*[s]

=> cdefg


So it is not necessary to provide this feature again by the construct
with the last argument omitted.  We can use the 2-argument version of
.substring for other purposes, for example, to retrieve the character
for a single index.

More exactly, I propose to identify `.substring s n' with 
`.substring s n n' instead of the actual `.substring s n -1'.

Bernd Warken



reply via email to

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