From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Can Ada iterate over Nd array?
Date: Wed, 25 Apr 2012 22:36:24 -0700
Date: 2012-04-25T22:36:24-07:00 [thread overview]
Message-ID: <jnan0d$i2m$1@tornado.tornevall.net> (raw)
In-Reply-To: <slrnjphkhm.h4f.oka.sux@localhost.localdomain>
On 04/25/2012 09:42 PM, Okasu wrote:
> I can't iterate over Nd array in Ada, becuse of
>> expression for dimension must be static
> So following code won't work:
>
> for X in A'Range loop
> for Y in A'Range (X) loop
> null;
> end loop;
> end loop;
>
> Geez, guys, what if i have to work with 1000d array?
> How can i iterate over it?
I have no idea what you're trying to do.
Obviously you're expecting A to be square (or cubic, or hyper-cubic, or ...), to
have indices of an integer type, and to have lower bounds of 1. None of these
are necessarily true.
Multi-dimensional arrays need not be square, so A'range (X) might reference
dimensions of A that don't exist (if it were allowed).
Array indices can be of any discreet type, including enumeration types. I don't
know what A'range (Green) or A'range ('E') would mean.
Even if an array has integral indices, the lower bound need not be 1. Again,
A'range (X) might reference dimensions of A that don't exist.
I can't see what you'd have in place of "null;" for a 1000-dimension array. You
can reference the whole array (A) or index a specific component of A, which
requires as many indices as A has dimensions. You have 2 indices, X and Y; where
are you going to get the other 998 indices?
In general, you iterate over an N-dimensional by having N nested "for" loops, 1
for each dimension of the array:
type Three_D is array (1 .. 3, 7 .. 300, 'A' .. 'Z') of Integer;
A : Three_D;
for I in A'range (1) loop
for J in A'range (2) loop
for K in A'range (3) loop
-- Do something with A (I, J, K)
end loop;
end loop;
end loop;
--
Jeff Carter
"Ada has made you lazy and careless. You can write programs in C that
are just as safe by the simple application of super-human diligence."
E. Robert Tisdale
72
next prev parent reply other threads:[~2012-04-26 5:36 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 [this message]
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
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