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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Arrays in Ada 2012 Date: Tue, 06 Jun 2017 14:17:01 +0100 Organization: A noiseless patient Spider Message-ID: References: <35c6ac5a-3295-4fa4-8545-ca76c113dde4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="8c9a2d9d2b8fbe112d52994a4f388f04"; logging-data="20630"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jFSIP6+124LlndTP/N2hAxHCs5s9IXjU=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (darwin) Cancel-Lock: sha1:bOp9IigIxS8Ne5ToZOAzu6a/TAY= sha1:mjoz4k5vpYrK5fMDbqjJo4GKacQ= Xref: news.eternal-september.org comp.lang.ada:46899 Date: 2017-06-06T14:17:01+01:00 List-Id: "Dmitry A. Kazakov" 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