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-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Surprise in array concatenation Date: 05 Sep 2005 17:48:14 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1125610942.747981.280770@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1125956894 13893 192.74.137.71 (5 Sep 2005 21:48:14 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 5 Sep 2005 21:48:14 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:4453 Date: 2005-09-05T17:48:14-04:00 List-Id: tmoran@acm.org writes: > >I completely agree with the marginal utility of other-than-1 least > >array indices. > I strongly disagree. While not dirt common, other 'firsts in > declarations do occur. -n .. +n comes to mind. Heh? "Marginal utility" means the same as "not dirt common"! My suggestion was that the language should _allow_ the programmer to fix the lower bound for an array type. And/or the upper bound. In Ada, you can fix both or neither -- but not one or the other. Anyway, you'd still be allowed to do your -n..+n thing, in the rare cases where that's useful. >... If you are going to > handle slices, you have to assume 'first /= 1 anyway,... No, I don't. ;-) Slices should slide to the lower bound. The Ada rule breaks abstraction: 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. >... so you're not losing > much by allowing it in declarations. Using 'first instead of 1 also makes > it simple to change between integer and enumeration value indexes. The > way Ada.Text_IO.Get_Line (et al) returns Last, which works even if you > passed it a slice, has surely prevented many an error as compared to other > languages which would likely return a count (since "all arrays start at > x") and depend on the programmer to do any arithmetic needed to turn it > into an index. And if you started all arrays at 1, I wouldn't insist on starting _all_ arrays at 1, but I think it makes sense for _many_ arrays, including String. >... you probably wouldn't > allow the idiom > subtype cards is string(1 .. 80); > subtype sequence is range 73 .. 80; > ... > if card(sequence) = (sequence=>' ') then Why not? In Ada, "=" doesn't care about the bounds -- just the length. - Bob