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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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-13 04:53:59 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn12feed!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Reply-To: "James S. Rogers" From: "James S. Rogers" Newsgroups: comp.lang.ada References: <3EC0494F.A7D67AA4@bellsouth.net> Subject: Re: array slices X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: Date: Tue, 13 May 2003 11:53:59 GMT NNTP-Posting-Host: 12.86.38.231 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1052826839 12.86.38.231 (Tue, 13 May 2003 11:53:59 GMT) NNTP-Posting-Date: Tue, 13 May 2003 11:53:59 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:37271 Date: 2003-05-13T11:53:59+00:00 List-Id: "gshibona @ b e l l s o u t h . n e t" wrote in message news:3EC0494F.A7D67AA4@bellsouth.net... > 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); > > -- however, this does not... > a(1..4) := c(1)(1..4); > > end ada_2daryslice; > > The compiler complains of too few subscripts in the array reference. Others have noted that you can only slice a one dimensional array. I will focus on another issue in your code. This error message is correct. You defined array c as a two dimensional array. You are accessing it as an array of arrays. Those are two different concepts in Ada. To access the elemets of array c you want to use the following syntax: c(1,1) Note that this is different from c(1)(1) Your problem can be better resolved using an array of arrays. type Row is array (1..4) of integer; type Matrix is array (1..2) of Row; a : Row := (1,2,3,4); c : Matrix := (1 =>(0,1,2,4), 2 => (8,16,32,64)); a := c(1); This works because each element of C is a Row as defined above. A is also a Row. You can also do the following: a(1..2) := c(2)(3..4); Jim Rogers