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,35edde140291c79e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.211.136 with SMTP id nc8mr5454224pbc.6.1335512376264; Fri, 27 Apr 2012 00:39:36 -0700 (PDT) Path: r9ni103594pbh.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Can Ada iterate over Nd array? Date: Fri, 27 Apr 2012 00:39:35 -0700 (PDT) Organization: http://groups.google.com Message-ID: <29536085.12.1335512375723.JavaMail.geo-discussion-forums@yndm3> References: <18y0zty0yw1m3.1dkfnp5etqdk0$.dlg@40tude.net> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 X-Trace: posting.google.com 1335512376 9567 127.0.0.1 (27 Apr 2012 07:39:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 27 Apr 2012 07:39:36 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-04-27T00:39:35-07:00 List-Id: On Friday, April 27, 2012 2:58:49 AM UTC+1, Jerrid Kimball wrote: > bOn 04/26/2012 07:36 PM, Randy Brukardt wrote: > > "Dmitry A. Kazakov" wrote in message > > news:18y0zty0yw1m3.1dkfnp5etqdk0$.dlg@40tude.net... > >> On Thu, 26 Apr 2012 06:02:13 +0000 (UTC), Okasu wrote: > >> > >>> So you trying to say that i have to write loops for 10/100/1000d arrays > >>> by hand? > >> > >> You should introduce an index type of your own (a Nth tuple) and use a > >> flat > >> container, e.g. a map over that index. > >> > >> Unfortunately Ada does not have 1st class indices, which was #10 in my > >> wish > >> list for Ada 202X. > > > > It does, however, have 2nd class indices (see 4.1.6), which work better than > > first class indicies most of the time. > > > > Also, you can iterate over the entire array without using any indicies in > > Ada 2012: > > > > for E of A loop > > null; > > end loop; > > > > This also works for containers. > > > > But this doesn't work in earlier versions of Ada. > > > > Randy. > > > > > > And in a recent GNAT wavefront, it seems to only work for > one-dimensional arrays. Otherwise, you get an error "too few subscripts > in array reference" which doesn't make a lot of sense. This is 7.1w > from January, but supposedly 7.0 has full 2012 support. I've noticed a > lot of problems in this wavefront regarding 2012 support so hopefully > they're not issues in 7.0 stable. This works for me with GNAT PRO v7.0.1: with Ada.Text_IO; use Ada.Text_IO; procedure Multi_D_Arrays is type A is array (1 .. 3) of Integer; type B is array (1 .. 4) of A; type C is array (1 .. 2) of B; procedure Set (A_C : in out C; Value : in Integer) is V : Integer := Value; begin for I of A_C loop for J of I loop for K of J loop K := V; V := V + 1; end loop; end loop; end loop; end Set; procedure Display (A_C : C) is begin for I of A_C loop for J of I loop for K of J loop Put_Line (Integer'Image (K)); end loop; end loop; end loop; end Display; My_C : C; begin Set (My_C, 0); Display (My_C); Set (My_C, 10_000); Display (My_C); end Multi_D_Arrays; Gives: D:\Ada\multi_d_arrays\lib\multi_d_arrays 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 [2012-04-27 08:38:39] process terminated successfully (elapsed time: 00.11s) -- Martin