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: a07f3367d7,59068e2a5e83c802 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!g1g2000pra.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Indexing unconstrained arrays Date: Mon, 31 Aug 2009 08:29:14 -0700 (PDT) Organization: http://groups.google.com Message-ID: <35fd001e-038b-42db-8749-eb435f671cde@g1g2000pra.googlegroups.com> References: <7de92fda-d0e3-4b6a-82e3-71881536c8b6@d4g2000prc.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1251732555 11743 127.0.0.1 (31 Aug 2009 15:29:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 31 Aug 2009 15:29:15 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g1g2000pra.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8073 Date: 2009-08-31T08:29:14-07:00 List-Id: On Aug 29, 9:43=A0pm, Rick wrote: > If I have an unconstrained array progressively built from a NULL array > > My_Array : Unconstrained_Array_Type (1 .. 0); > > to an array of five cells, it should be indexed 1 .. 5. =A0Suppose then > that I remove cell My_Array (3) by a bit of slicing and splicing. > > Does the indexing of the four-cell array that is left run > > 1 - 2 - 3 - 4 > > or does it run > > 1 - 2 - 4 - 5 ? > We'd need to see your exact code to give an exact answer. But as you've hopefully figured out by now, you can't really "grow" an array, in the sense that you can't make an array larger (or smaller) that you've already declared. (At least not with a simple Ada "array" type. There are probably ways to use Ada.Containers to achieve that.) What you can do is to create a new array. So your code that progressively builds an array may look something like this: My_Array :=3D new Unconstrained_Array_Type (1 .. 0); for I in 1 .. Something loop New_Element :=3D ...; My_Array :=3D new Unconstrained_Array_Type' (My_Array.all & New_Element); end loop; which progressively adds a New_Element to the end of each array. (The above wastes a lot of storage, so you need to do a little more to avoid the wastage, but I'm just trying to demonstrate the basic concept.) Now, if My_Array has five elements in the range 1 .. 5, and you do something like this: My_Array :=3D new Unconstrained_Array_Type' (My_Array(1..2) & My_Array(4..5)); The result will be a four-element array. The actual bounds of the result are given by RM 4.5.3; one of the rules is that if the array type is unconstrained, and the left operand is not a null array, then the lower bound of the result is the lower bound of the left operand. Here, the lower bound of the left operand is 1 (since a slice using M..N will have bounds M and N), therefore the lower bound of the result is 1. The upper bound of the result will then be 4, since the indexes in an array are always sequential. That is, the indexes of the elements of the result would be 1, 2, 3, 4. If you want an array with indexes 1-2-4-5, then what you want is an associative array, where array elements are indexed by a **key** instead of by a simple index. Ada's basic array type is *not* that kind of array. If you do want something like that, I think you want one of the "map" types provided by Ada.Containers. -- Adam