Paddy O'Brien writes:
> Richard Maine wrote:
> > Be aware that x(:) and x do not mean the same thing.
> If an array is declared with a lower bound, why does a "slice" start at
> 1 not the declared lower bound? Then x and x(:) are equivalent.
Because there is no rule that will give a "reasonable" answer for
all cases. I can't even tell you what "the declared lower bound"
means in anything except the simplest cases. In other cases, I
can tell you what it means, but that would be the intuitively
"wrong" value. I'm not willing to play the "you propose a rule
and I'll show you a problem with it" game, because that "game"
has been played many times already. It takes a long time to
finish and always comes back to the same answer - that there
isn't a universally good rule. The rule in the standard does
have 2 advantages
1. It is well defined in every case (this is important for a
standard). This is a property many rules don't have. (For
example, the "declared lower bound" rule that you suggest).
2. It is at least simple.
P.S. I will play round 1 of the game. If x has a declard lower
bound of 0, what is the lower bound of x(3:10)? Is it 0
(because that's the declared lower bound of x)? Perhaps 3 (from
the 3 in the range)? Or 4 (because element 3 is the 4th one)?
All of those answers would have adherents. For the next
round, consider x(10:3:-2). Then continue with expressions
involving multiple arrays. Perhaps vector-valued subscripts.
And in the end, if you can answer every question to your
satisfaction, then try to get a majority of other users to
agree that the answers that make sense to you also make
sense to them. If you can do all that, you win the game
(and perhaps ought to be helping us write standards, because
you've got better skills both at abstraction and at persuasion
than I do).
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|