|
From: Juergen W. <wie...@fr...> - 2005-07-06 07:09:36
|
Am Montag, 4. Juli 2005 20:38 schrieb Ethan A Merritt:
> On Monday 04 July 2005 01:10 am, you wrote:
> > Secondly, and probably too late: word("s t r i n g", 1) fishes the
> > first word ("s"), while substr("string",1,1) returns the second
> > letter. I think both indices should start at the same value.
> > Don't know how to solve this.
>
> I don't know either. Perhaps I should just remove the substr()
> function altogether. That would make a clear distinction between
> the operation STRING[beg:end] (uses C-language indexing from 0)
> and the function calls like word(STRING,N) (uses rexx or fortran
> indexing starting from 1).
Well, STRING[beg:end] is not exactly C syntax. The bracket may be C
style, but the is like Fortran style. I vote for 1 as start index
even here.
> I don't think it's too late to change these; they've only been
> in CVS for a short time. The question did come up in discussion,
> but few opinions or answers were offered. I chose to go with logic
> that if the function name came from a particular environment, rexx
> in the case of word() and words(), it should maintain the indexing
> convention that it was derived from.
>
> But I agree that the substr(beg,end) indexing is confusing, and
> contradicts the awk equivalent substr(beg,length) regardless
> of whether beg starts at 0 or 1.
It's not that easy to notice that STRING[beg:end] also works on
general string expressions. And to use it in these cases is not
very elegant. BTW: What precedence does this operator have. I
couldn't find it at "help operators".
Juergen
|