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!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.11) Gecko/20050728 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Surprise in array concatenation References: <1125544603.561847.32140@g47g2000cwa.googlegroups.com> <1125610942.747981.280770@f14g2000cwb.googlegroups.com> In-Reply-To: <1125610942.747981.280770@f14g2000cwb.googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <%s2Se.3982$4P5.1499@newsread2.news.pas.earthlink.net> Date: Fri, 02 Sep 2005 20:19:07 GMT NNTP-Posting-Host: 4.240.33.152 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.pas.earthlink.net 1125692347 4.240.33.152 (Fri, 02 Sep 2005 13:19:07 PDT) NNTP-Posting-Date: Fri, 02 Sep 2005 13:19:07 PDT Xref: g2news1.google.com comp.lang.ada:4412 Date: 2005-09-02T20:19:07+00:00 List-Id: Gene wrote: > I completely agree with the marginal utility of other-than-1 least > array indices. Then you need a lot more experience. There is great utility to arrays with lower bounds other than 1, and to arrays with non-numeric bounds. 30 years ago, when I became a coder, I worked in dendroclimatology, attempting to determine the climate of the past from tree-ring information. We had code with big arrays of tree-ring data, all indexed from 1, of course, since this was in FORTRAN 66, and other arrays of climate data. The tree-ring data started with values from some year in the past, such as 1600, and the climate data in 1895 or so. The code was liberally sprinkled with calculations to convert between the logical indices (years) and the actual indices (1 .. # of years). Different calculations had to be used for the 2 data sets, I didn't capture the algorithms in functions because I didn't know any better, and sometimes I managed to use the wrong calculation. Ah, those were the days! How much easier it would have been if I could simply have indexed these things from 1600 .. 1965 and 1895 .. 1965. (Having record types would have helped, too.) This helps explain the popularity of C and its descendants: It gives a real feeling of accomplishment to do this kind of thing successfully, even though it contributes nothing to the solution of the real problem being addressed. The problem in the example is that the code defines an array type with "Integer range <>", allowing any lower bound in Integer, and proceeds to assume that all values of the type have lower bound of 1. That's a simple implementation error. Had the implementor recognized that values of the type may have any lower bound in Integer, and used 'First rather than an incorrect magic number, the problem would not have appeared. If there is a requirement that the values have a lower bound of 1, there's an Ada mechanism for that: type A is array (Positive range <>) of Whatever; type Lower_Bound_Always_1 (Length : Natural) is record Value : A (1 .. Length); end record; Even then, one should still use 'First. -- Jeff Carter "I fart in your general direction." Monty Python & the Holy Grail 05