Re: Surprise in array concatenation
- From: "Bob Spooner" <rls19@xxxxxxx>
- Date: Tue, 6 Sep 2005 09:22:52 -0400
"Robert A Duff" <bobduff@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:wccoe77nq3l.fsf@xxxxxxxxxxxxxxxxxxxxxxx
> tmoran@xxxxxxx writes:
>
snip...
>
> Slices should slide to the lower bound. The Ada rule breaks
> abstraction:
So if I pass a subprogram a slice of an array indexed by an enumeration type
then the mapping of the values to the enumeration type should change?
>
> procedure P(X: String) is
> begin
> ...
> end P;
>
> Y: String := "Hello, world!";
>
> P(Y(3..4));
>
> Inside the body of P, X is just a String -- we don't (or shouldn't) know
> that it's a substring of Y. So we can't possibly make any sense (inside
> P) of the fact that X'First = 3. Index 3 from what?
>
> If I ran the circus, X'First would be 1.
>
But that would make String a special case of an array if you allow other
arrays to start with a value other than the first value of the index type.
Yet another thing we would have to remember...
>
> I wouldn't insist on starting _all_ arrays at 1, but I think it makes
> sense for _many_ arrays, including String.
>
Many other special cases to remember as well?
snip...
>
> - Bob
In my view, the abstraction that is important here is that of the array
rather than that of the subprogram seeing a slice as always beginning with
Index'first. The characteristics of the abstraction of an array should be as
consistent in Ada as possible. While having the first value of a String and
whatever types of arrays you think are appropriate always be the first value
of the index type would save some memory and computation time, Ada is one of
the few languages where the array is a powerful and safe abstraction. It is
therefore much more useful than in other languages, making consistency of
behavior all the more important and, I think, worth the price in
computation. To make arrays robust and safe in C type languages, for
instance, involves adding a lot more baggage than an extra integer value and
a little bit of computation done transparently by the compiler.
Bob
.
- Follow-Ups:
- Re: Surprise in array concatenation
- From: Robert A Duff
- Re: Surprise in array concatenation
- References:
- Re: Surprise in array concatenation
- From: Gene
- Re: Surprise in array concatenation
- From: tmoran
- Re: Surprise in array concatenation
- From: Robert A Duff
- Re: Surprise in array concatenation
- Prev by Date: Re: Surprise in array concatenation
- Next by Date: Re: Surprise in array concatenation
- Previous by thread: Re: Surprise in array concatenation
- Next by thread: Re: Surprise in array concatenation
- Index(es):
Relevant Pages
|