comp.lang.ada
 help / color / mirror / Atom feed
From: Martin <martin@thedowies.com>
Subject: Re: Can Ada iterate over Nd array?
Date: Fri, 27 Apr 2012 00:39:35 -0700 (PDT)
Date: 2012-04-27T00:39:35-07:00	[thread overview]
Message-ID: <29536085.12.1335512375723.JavaMail.geo-discussion-forums@yndm3> (raw)
In-Reply-To: <jncugr$9s1$1@munin.nbi.dk>

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"<mailbox@dmitry-kazakov.de>  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



  reply	other threads:[~2012-04-27  7:39 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-26  4:42 Can Ada iterate over Nd array? Okasu
2012-04-26  5:36 ` Jeffrey Carter
2012-04-26  6:02   ` Okasu
2012-04-26  6:05     ` Okasu
2012-04-26 10:57       ` ytomino
2012-04-26  8:01     ` Dmitry A. Kazakov
2012-04-27  0:36       ` Randy Brukardt
2012-04-27  1:58         ` Jerrid Kimball
2012-04-27  7:39           ` Martin [this message]
2012-04-27 18:08             ` Jeffrey Carter
2012-04-30  7:20               ` Martin
2012-04-30 13:21                 ` Robert A Duff
2012-04-30 15:42                   ` Martin
2012-04-27 16:06         ` Shark8
2012-04-26  9:00     ` Georg Bauhaus
2012-04-26 15:48     ` Adam Beneschan
2012-04-26 20:54       ` Okasu
2012-04-27  0:39       ` Randy Brukardt
2012-04-27 13:30         ` Robert A Duff
2012-04-28  8:24           ` Georg Bauhaus
2012-04-28  9:35             ` björn lundin
     [not found]               ` <raadncdcv9V-hgHSnZ2dnUVZ_v2dnZ2d@earthlink.com>
2012-04-28 23:19                 ` björn lundin
2012-04-30 14:48               ` gautier_niouzes
2012-05-01  2:02           ` Randy Brukardt
2012-04-27  4:19       ` Nasser M. Abbasi
2012-04-27 16:23       ` Bill Findlay
2012-04-26  9:40 ` gautier_niouzes
     [not found] ` <26754113.2767.1335431755764.JavaMail.geo-discussion-forums@vbki8>
2012-04-26 18:09   ` Jeffrey Carter
2012-04-27  0:28     ` BrianG
2012-04-27 13:46       ` Robert A Duff
2012-04-27 11:09 ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox