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,1cb75f0476fe2d1a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.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.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Half Constrained Array Types and Slices References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Fri, 03 Mar 2006 05:15:00 GMT NNTP-Posting-Host: 67.150.73.31 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1141362900 67.150.73.31 (Thu, 02 Mar 2006 21:15:00 PST) NNTP-Posting-Date: Thu, 02 Mar 2006 21:15:00 PST Xref: g2news1.google.com comp.lang.ada:3249 Date: 2006-03-03T05:15:00+00:00 List-Id: Robert A Duff wrote: > > (Except my hobby language can use this idea to _simplify_, whereas Ada > would have had to add this feature and still keep the "range <>" > notation for compatibility.) Right. I suppose you could introduce a notation like Positive range 1 .. <> to get a similar effect without having 2 ways to do an unconstrained array. > I'm not so sure about that. I'm inclined to say slices always slide to > the lower bound. The idea that X(3..5) should have lower bound 3 seems > to make sense at first, until you think about passing that slice as a > parameter. The called procedure should not care that it's a slice at > all -- much less the particular bounds used to create it. The Ada rule > violates abstraction. Same issue for function returns. OK. So you're saying a slice (Lo .. Hi) of an unconstrained array type would slide to Index'First .. Index'First + Hi - Lo? > Yes, I agree that's a problem. Various possible solutions come to > mind. Probably the simplest is to outlaw slices of constrained arrays. > After all, what is the sense in saying "all arrays of type T go from > 1 to 5", and then turn around and create values of type T with bounds > 3..4? Even in Ada as is, there is very little use for this feature. > You can do: > > type Bits is array(Int range 0..31) of Boolean; > > function Rotate(X: Bits) return Boolean Bits is > begin > return X(31) & X(0..30); > end Rotate; > > But that's not worth much language complexity. If you want that, > declare an unconstrained (doubly unconstrained?) array, along with > constrained subtype(s). That was the rule in Ada 83, IIRC. It apparently bit enough people that it was changed in Ada 95. > I can talk about more and more exotic ideas, depending on how far away > from Ada you're willing to contemplate. ;-) For example, I'd like to > be able to do: > > type T(D1: ...; D2: ...) is ... > subtype S is T(D1 => 17); -- Illegal in Ada to partially constrain! > > Or maybe the syntax should be "T(D1 => 17, D2 => <>)". In that case, this would be how you'd deal with slices of half-constrained arrays if you wanted to keep the bounds; the base type would be unconstrained and the first-named subtype would be partially constrained. -- Jeff Carter "You cheesy lot of second-hand electric donkey-bottom biters." Monty Python & the Holy Grail 14