[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] changed .substring
From: |
Werner LEMBERG |
Subject: |
Re: [Groff] changed .substring |
Date: |
Fri, 12 Jul 2002 04:17:02 +0200 (CEST) |
> 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".
Note that both Emacs and Python have a third `parameter' for the
substring operation: `:' in Python and `nil' in Elisp which we don't
have in groff. You can say `s[0:]' and (substring 0 nil),
respectively, to get the full string. And in Python you can omit the
colon to access a single element.
> 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.
I can live with that. :-)
Even after some thinking I can't find the real advantages of using a
[start,end[ range (i.e., including start but excluding end). And
there is no way to specify the full range of a string if the second
argument counts from the end: In Python, this would be [0:(-1+1)] =
[0:0] but this is the empty string (not very useful in a substring
operation IMHO).
> 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'.
I don't have an opinion here. For me, both Bernd's suggestion
(resembling Python) and the current implementation (resembling Elisp)
make sense.
What do others think?
Please answer quickly! I really, really want to release 1.18, but we
have to agree on the new .substring syntax before since I won't change
it again.
Werner