From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,db88d0444fafe8eb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!news.aset.psu.edu!not-for-mail From: "Bob Spooner" Newsgroups: comp.lang.ada Subject: Re: Surprise in array concatenation Date: Tue, 6 Sep 2005 09:22:52 -0400 Organization: Penn State University, Center for Academic Computing Message-ID: References: <1125610942.747981.280770@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: nat3.arl.psu.edu X-Trace: f04n12.cac.psu.edu 1126012976 31612 128.118.40.78 (6 Sep 2005 13:22:56 GMT) X-Complaints-To: usenet@f04n12.cac.psu.edu NNTP-Posting-Date: Tue, 6 Sep 2005 13:22:56 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 Xref: g2news1.google.com comp.lang.ada:4471 Date: 2005-09-06T09:22:52-04:00 List-Id: "Robert A Duff" wrote in message news:wccoe77nq3l.fsf@shell01.TheWorld.com... > tmoran@acm.org 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