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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1f8b4cce7e72b123 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-25 22:39:10 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!wn1feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc06-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3BD8F70E.3667B286@worldnet.att.net> From: James Rogers X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Arrays and Access types... References: <20011025214647.2788a60b.egm2@jps.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 26 Oct 2001 05:39:09 GMT NNTP-Posting-Host: 12.86.33.221 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc06-news.ops.worldnet.att.net 1004074749 12.86.33.221 (Fri, 26 Oct 2001 05:39:09 GMT) NNTP-Posting-Date: Fri, 26 Oct 2001 05:39:09 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:15213 Date: 2001-10-26T05:39:09+00:00 List-Id: Unlike C, Ada arrays are not directly related to access types or pointers. There are several ways to solve your problem. My personal approach would be to create a record structure to keep track of your slicing on a single array element. One such data structure follows: --- Slicable array package generic Max_Size : Positive; type Element is private; package Slicing_Array is subtype Array_Index is Positive range 1..Max_Size; type Element_Array is array(Array_Index range <>) of Element; type Slicable_Array is private; function Create(Item : Element_Array) return Slicable_Array; function First(Item : Slicable_Array) return Positive; function Last(Item : Slicable_Array) return Positive; function To_Array(Item : Slicable_Array) return Element_Array; procedure Slice(Item : in out Slicable_Array; First : Positive; Last : Positive); Bounds_Error : Exception; -- When slicing beyond the array bounds private type Slicable_Array is record First : Positive := 1; Last : Positive := Max_Size; Buffer : Element_Array(Array_Index'Range); end record; end Slicing_Array; --- Slicable array package package body Slicing_Array is function Create(Item : Element_Array) return Slicable_Array is Result : Slicable_Array; begin Result.Last := Item'Length; Result.Buffer(1..Result.Last) := Item; return Result; end Create; function First(Item : Slicable_Array) return Positive is begin return Item.First; end First; function Last(Item : Slicable_Array) return Positive is begin return Item.Last; end Last; function To_Array(Item : Slicable_Array) return Element_Array is begin return Item.Buffer(Item.First..Item.Last); end To_Array; procedure Slice(Item : in out Slicable_Array; First : Positive; Last : Positive) is begin if First not in Array_Index or Last not in Array_Index then raise Bounds_Error; end if; Item.First := First; Item.Last := Last; end Slice; end Slicing_Array; Jim Rogers Colorado Springs, Colorado USA "Eric G. Miller" wrote: > > New to Ada and trying to figure out how to deal with arbitrary > slices of arrays. I defined an array type and an access type > for it, but I can't seem to figure out how to take a slice of > the array and assign that slice to an access type. > ... > > What I want to do is progressively subset the array, and I > won't know exactly how it'll get broken up until runtime. The > original array will get divvied up into smaller and smaller > slices of an earlier slice (the remaining can be discarded).