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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no 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 nc8mr1959450pbc.6.1335418594815; Wed, 25 Apr 2012 22:36:34 -0700 (PDT) Path: r9ni99530pbh.0!nntp.google.com!news2.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!81.171.88.16.MISMATCH!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder3.xlned.com!feeder.erje.net!newsfeed.datemas.de!news.tornevall.net!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Can Ada iterate over Nd array? Date: Wed, 25 Apr 2012 22:36:24 -0700 Organization: TornevallNET - http://news.tornevall.net Message-ID: References: NNTP-Posting-Host: 36213acb47107a8a274b6149ffb3c5c5 Mime-Version: 1.0 X-Trace: 6a616c3874858a9ab7ef2ec7e88e9083 X-Complaints-To: abuse@tornevall.net User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 X-Complaints-Language: Spoken language is english or swedish - NOT ITALIAN, FRENCH, GERMAN OR ANY OTHER LANGUAGE! In-Reply-To: X-UserIDNumber: 1738 X-Validate-Post: http://news.tornevall.net/validate.php?trace=6a616c3874858a9ab7ef2ec7e88e9083 X-Complaints-Italiano: Non abbiamo padronanza della lingua italiana - se mandate una email scrivete solo in Inglese, grazie X-Posting-User: 0243687135df8c4b260dd4a9a93c79bd Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-04-25T22:36:24-07:00 List-Id: 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