From: Simon Wright <simon@pushface.org>
Subject: Re: Arrays in Ada 2012
Date: Tue, 06 Jun 2017 14:17:01 +0100
Date: 2017-06-06T14:17:01+01:00 [thread overview]
Message-ID: <lylgp5tfw2.fsf@pushface.org> (raw)
In-Reply-To: oh66gg$19oa$1@gioia.aioe.org
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> On 06/06/2017 13:47, Anatoly Chernyshev wrote:
>
>> Consider the following nice Ada 2012 construct:
>>
>> --
>> procedure test is
>> type a1 is array(1..35,1..35,1..35,1..35,1..35,1..35) of long_long_integer;
>> ab:a1;
>> cnt:long_long_integer:=0;
>> begin
>> for e of ab loop
>> cnt:=cnt+1;
>> e:=cnt;
>> end loop;
>> end test;
>> --
>>
>> Is there a way (e.g. some attribute) to find the indices of the
>> array for a current e within the cycle above?
>
> The greater dimension index changes first, so:
I don't think this is right? it's the last index that changes first,
with Ada.Text_IO; use Ada.Text_IO;
procedure Arrays is
type A1 is array (0 .. 1, 41 .. 42) of Integer;
A : A1 := ((1, 2), (3, 4));
begin
for E of A loop
Put (E'Img);
end loop;
New_Line;
for J in A'Range (1) loop
for K in A'Range (2) loop
Put_Line (J'Img & K'Img & A (J, K)'Img);
end loop;
end loop;
end Arrays;
produces
$ ./arrays
1 2 3 4
0 41 1
0 42 2
1 41 3
1 42 4
> I6 := Count mod 35 + 1;
> I5 := (Count / 35) mod 35 + 1;
> I4 := (Count / 35**2) mod 35 + 1;
> I3 := (Count / 35**3) mod 35 + 1;
> I2 := (Count / 35**4) mod 35 + 1;
> I1 := Count / 35**5 + 1;
Should be able to use 'Length (N) in there!
ARM 3.6.2(10),
http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-3-6-2.html#p10
next prev parent reply other threads:[~2017-06-06 13:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 11:47 Arrays in Ada 2012 Anatoly Chernyshev
2017-06-06 12:17 ` Dmitry A. Kazakov
2017-06-06 13:17 ` Simon Wright [this message]
2017-06-06 13:57 ` Dmitry A. Kazakov
2017-06-06 21:59 ` Simon Wright
2017-06-06 13:19 ` AdaMagica
2017-06-06 20:56 ` Randy Brukardt
2017-06-07 7:06 ` Dmitry A. Kazakov
2017-06-07 11:47 ` Anatoly Chernyshev
2017-06-07 12:15 ` Dmitry A. Kazakov
2017-06-08 0:55 ` Randy Brukardt
2017-06-08 0:51 ` Randy Brukardt
2017-06-08 7:07 ` Dmitry A. Kazakov
2017-06-09 3:23 ` Randy Brukardt
2017-06-18 2:14 ` Arrays in Ada 2020 Ivan Levashev
2017-06-18 3:00 ` Nasser M. Abbasi
2017-06-18 12:06 ` Robert Eachus
2017-06-18 20:15 ` Simon Wright
2017-06-20 13:33 ` Robert Eachus
2017-06-19 6:36 ` Ivan Levashev
2017-06-19 12:06 ` AdaMagica
2017-06-23 1:17 ` Randy Brukardt
2017-06-18 20:15 ` Pascal Obry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox