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,5fc9b87ca6f5fbaf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-12 18:30:13 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!207.217.77.102!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3EC04A91.3060905@spam.com> From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: array slices References: <3EC0494F.A7D67AA4@bellsouth.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 13 May 2003 01:28:09 GMT NNTP-Posting-Host: 63.184.16.17 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1052789289 63.184.16.17 (Mon, 12 May 2003 18:28:09 PDT) NNTP-Posting-Date: Mon, 12 May 2003 18:28:09 PDT Xref: archiver1.google.com comp.lang.ada:37255 Date: 2003-05-13T01:28:09+00:00 List-Id: gshibona @ b e l l s o u t h . n e t wrote: > I wonder if someone could point to the error in this code. I'm looking > to fill array a with a "row" slice > of array c. There doesn't appear to be much info on this particular > facet of Ada, yet what I have seen > suggests that the syntax below is correct. > > procedure ada_2daryslice is > > a : array(1..4) of integer; > c : array( 1..2, 1..4 ) of integer; > > begin > c := ( > 1 => (0, 1, 2, 4 ), > 2 => (8, 16, 32, 64) > ); > -- this seems to yield the expected results > a(1..4) := ( 1,2,3,4); This is perhaps better written as A := (1, 2, 3, 4); > > -- however, this does not... > a(1..4) := c(1)(1..4); > > end ada_2daryslice; You can only slice a one-dimensional array. C is a two-dimensional array, and must have 2 indices. C (1) is meaningless here. You have 2 choices. Well, you probably have more, but 2 main ones: 1. Use a loop for I in A'range loop A (I) := C (C'First, I); end loop; 2. Make C a one-dimensional array of one-dimensional arrays (this is not the same thing as a two-dimensional array): type One_D is array (1 .. 4) of Integer; A : One_D; C : array (1 .. 2) of One_D; ... A := C (1); -- Jeff Carter "Monsieur Arthur King, who has the brain of a duck, you know." Monty Python & the Holy Grail