comp.lang.ada
 help / color / mirror / Atom feed
* Can Ada iterate over Nd array?
@ 2012-04-26  4:42 Okasu
  2012-04-26  5:36 ` Jeffrey Carter
                   ` (3 more replies)
  0 siblings, 4 replies; 31+ messages in thread
From: Okasu @ 2012-04-26  4:42 UTC (permalink / raw)


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?



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  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  9:40 ` gautier_niouzes
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 31+ messages in thread
From: Jeffrey Carter @ 2012-04-26  5:36 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26  5:36 ` Jeffrey Carter
@ 2012-04-26  6:02   ` Okasu
  2012-04-26  6:05     ` Okasu
                       ` (3 more replies)
  0 siblings, 4 replies; 31+ messages in thread
From: Okasu @ 2012-04-26  6:02 UTC (permalink / raw)


On 2012-04-26, Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> wrote:
>
> 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;
>

It's a brain dead code.
So you trying to say that i have to write loops for 10/100/1000d arrays
by hand?



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  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
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 31+ messages in thread
From: Okasu @ 2012-04-26  6:05 UTC (permalink / raw)


On 2012-04-26, Okasu <oka.sux@gmail.com> wrote:
> for X in A'Range loop
>     for Y in A'Range (X) loop
>        null;
>     end loop;
> end loop;

This is just an abstraction to show how should work iteration over
multidimensional array, nothing else.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26  6:02   ` Okasu
  2012-04-26  6:05     ` Okasu
@ 2012-04-26  8:01     ` Dmitry A. Kazakov
  2012-04-27  0:36       ` Randy Brukardt
  2012-04-26  9:00     ` Georg Bauhaus
  2012-04-26 15:48     ` Adam Beneschan
  3 siblings, 1 reply; 31+ messages in thread
From: Dmitry A. Kazakov @ 2012-04-26  8:01 UTC (permalink / raw)


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.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26  6:02   ` Okasu
  2012-04-26  6:05     ` Okasu
  2012-04-26  8:01     ` Dmitry A. Kazakov
@ 2012-04-26  9:00     ` Georg Bauhaus
  2012-04-26 15:48     ` Adam Beneschan
  3 siblings, 0 replies; 31+ messages in thread
From: Georg Bauhaus @ 2012-04-26  9:00 UTC (permalink / raw)


On 26.04.12 08:02, Okasu wrote:
> On 2012-04-26, Jeffrey Carter<spam.jrcarter.not@spam.not.acm.org>  wrote:
>>
>> 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;
>>
>
> It's a brain dead code.
> So you trying to say that i have to write loops for 10/100/1000d arrays
> by hand?

This will depend on your arrays.

With typical languages, typically, yes. Like in C, C++, Fortran, Pascal,
Lisp, ML, OCaml, Java, etc etc, arrays in Ada are basic. Array indexing
uses the same scheme as everyone else, except that Ada lets you
specify 'Range, 'First, and so on, no mishaps there. Even for an
array of dimension 1000, the scheme does not change in any of
these  languages.

(I will be very interested in seeing an array of dimension 1000
that isn't sparse.)

APL, SETL, R, and other languages are different.

When there is some library made for arrays, it can allow notions
such as "apply a subprogram Proc (First, Last: Vector) to the
block of dimension N between First and Last" where
N = Length(First) = Length(Last). There are some such libraries
for Ada, even in its standard  library.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26  4:42 Can Ada iterate over Nd array? Okasu
  2012-04-26  5:36 ` Jeffrey Carter
@ 2012-04-26  9:40 ` gautier_niouzes
       [not found] ` <26754113.2767.1335431755764.JavaMail.geo-discussion-forums@vbki8>
  2012-04-27 11:09 ` Stephen Leake
  3 siblings, 0 replies; 31+ messages in thread
From: gautier_niouzes @ 2012-04-26  9:40 UTC (permalink / raw)


Le jeudi 26 avril 2012 06:42:29 UTC+2, Okasu a écrit : 

> Geez, guys, what if i have to work with 1000d array? 

Even by programming on all sorts of projects, there are good chances are you'll never need more than a few array dimensions in your entire active life. 

We could make a poll here: which is the maximum number of array dimensions you ever used ? 
My answer: probably 5 or 6. 
And with very specific animals as indices: some enumerated types including Boolean, plus a few ranges. No reason not to write explicitly the loops. 
_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26  6:05     ` Okasu
@ 2012-04-26 10:57       ` ytomino
  0 siblings, 0 replies; 31+ messages in thread
From: ytomino @ 2012-04-26 10:57 UTC (permalink / raw)


   declare
      Liner_A : array(1..A'Size / A'Component_Size) of the element type of A;
      for Liner_A'Address use A'Address;
   begin
      for I in Liner_A'Range loop
         null;
      end loop;
   end;



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26  6:02   ` Okasu
                       ` (2 preceding siblings ...)
  2012-04-26  9:00     ` Georg Bauhaus
@ 2012-04-26 15:48     ` Adam Beneschan
  2012-04-26 20:54       ` Okasu
                         ` (3 more replies)
  3 siblings, 4 replies; 31+ messages in thread
From: Adam Beneschan @ 2012-04-26 15:48 UTC (permalink / raw)


On Wednesday, April 25, 2012 11:02:13 PM UTC-7, Okasu wrote:
> On 2012-04-26, Jeffrey Carter wrote:
> >
> > 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;
> >
> 
> It's a brain dead code.
> So you trying to say that i have to write loops for 10/100/1000d arrays
> by hand?

I don't think I've *ever* seen an array with more than three dimensions ever used, in 35 years of programming.  (Exception: I think I once created a 4-dimensional array in APL in an attempt to write a one-line function to do something complicated.  But that's more of a game, not really programming.)  If you really need a way to associate arbitrarily long tuples with elements, you probably should be using some other kind of structure than an array.

But I think Ada 2012 does support what you're looking for; see the example at the bottom of 5.5.2 (http://www.ada-auth.org/standards/12rm/html/RM-5-5-2.html).

                    -- Adam



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
       [not found] ` <26754113.2767.1335431755764.JavaMail.geo-discussion-forums@vbki8>
@ 2012-04-26 18:09   ` Jeffrey Carter
  2012-04-27  0:28     ` BrianG
  0 siblings, 1 reply; 31+ messages in thread
From: Jeffrey Carter @ 2012-04-26 18:09 UTC (permalink / raw)


On 04/26/2012 02:15 AM, gautier.de.montmollin@gmail.com wrote:
>
> We could make a poll here: which is the maximum number of array dimensions you ever used ?
> My answer: probably 5 or 6.

I don't recall ever using more than 3.

I don't think arrays with more than about 30 dimensions are going to be possible 
with current technology: given only 2 index values/dimension, that's 2 ** 30 
components, or 1 GB if each component is a byte. Much more than that and you 
won't be able to allocate the array. Even in the foreseeable future it doesn't 
look as if a 100-dimension array will be possible. 1000 dimensions is right out!

-- 
Jeff Carter
"I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
Mum! I'm a Red Sea pedestrian, and proud of it!"
Monty Python's Life of Brian
77



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26 15:48     ` Adam Beneschan
@ 2012-04-26 20:54       ` Okasu
  2012-04-27  0:39       ` Randy Brukardt
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 31+ messages in thread
From: Okasu @ 2012-04-26 20:54 UTC (permalink / raw)


On 2012-04-26, Adam Beneschan <adam@irvine.com> wrote:
> On Wednesday, April 25, 2012 11:02:13 PM UTC-7, Okasu wrote:
>> On 2012-04-26, Jeffrey Carter wrote:
>> >
>> > 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;
>> >
>>
>> It's a brain dead code.
>> So you trying to say that i have to write loops for 10/100/1000d arrays
>> by hand?
>
> I don't think I've *ever* seen an array with more than three dimensions ever used, in 35 years of programming.  (Exception: I think I once created a 4-dimensional array in APL in an attempt to write a one-line function to do something complicated.  But that's more of a game, not really programming.)  If you really need a way to associate arbitrarily long tuples with elements, you probably should be using some other kind of structure than an array.
>
> But I think Ada 2012 does support what you're looking for; see the example at the bottom of 5.5.2 (http://www.ada-auth.org/standards/12rm/html/RM-5-5-2.html).
>
>                     -- Adam

Thanks, it's exactly what i'm looking for, i'm happy to know that i can
easily iterate over any kind of array in Ada.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26 18:09   ` Jeffrey Carter
@ 2012-04-27  0:28     ` BrianG
  2012-04-27 13:46       ` Robert A Duff
  0 siblings, 1 reply; 31+ messages in thread
From: BrianG @ 2012-04-27  0:28 UTC (permalink / raw)


On 04/26/2012 02:09 PM, Jeffrey Carter wrote:
> On 04/26/2012 02:15 AM, gautier.de.montmollin@gmail.com wrote:
>>
>> We could make a poll here: which is the maximum number of array
>> dimensions you ever used ?
>> My answer: probably 5 or 6.
>
> I don't recall ever using more than 3.
>
> I don't think arrays with more than about 30 dimensions are going to be
> possible with current technology: given only 2 index values/dimension,
> that's 2 ** 30 components, or 1 GB if each component is a byte. Much
> more than that and you won't be able to allocate the array. Even in the
> foreseeable future it doesn't look as if a 100-dimension array will be
> possible. 1000 dimensions is right out!
>
If what is desired is an "n-dimensional array" (i.e. n is a parameter of 
some sort - generic or procedure parameter), what are you going to do 
with it, even if you can iterate?  How do you declare such a type?  If 
it's to be used as a library to work on "n-dimensional arrays", how do 
you specify subroutine parameters?  (Except as a raw memory address or 
equivalent.)

-- 
---
BrianG
000
@[Google's email domain]
.com



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  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 16:06         ` Shark8
  0 siblings, 2 replies; 31+ messages in thread
From: Randy Brukardt @ 2012-04-27  0:36 UTC (permalink / raw)


"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.





^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  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-27  4:19       ` Nasser M. Abbasi
  2012-04-27 16:23       ` Bill Findlay
  3 siblings, 1 reply; 31+ messages in thread
From: Randy Brukardt @ 2012-04-27  0:39 UTC (permalink / raw)


"Adam Beneschan" <adam@irvine.com> wrote in message 
news:393172.2032.1335455290715.JavaMail.geo-discussion-forums@yntt13...
...
>I don't think I've *ever* seen an array with more than three dimensions 
>ever used, in 35 years of programming.  (

I have (or had) a five dimension array in one of my programs. It was quite a 
problem to avoid running out of space (the size multiplies in a hurry!)

I think some of our internal test programs use 6 dimension arrays, under the 
assumption that no one will ever try to use more! But that was more of a 
white-box test than any real attempt to do anything.

                                   Randy.





^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27  0:36       ` Randy Brukardt
@ 2012-04-27  1:58         ` Jerrid Kimball
  2012-04-27  7:39           ` Martin
  2012-04-27 16:06         ` Shark8
  1 sibling, 1 reply; 31+ messages in thread
From: Jerrid Kimball @ 2012-04-27  1:58 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26 15:48     ` Adam Beneschan
  2012-04-26 20:54       ` Okasu
  2012-04-27  0:39       ` Randy Brukardt
@ 2012-04-27  4:19       ` Nasser M. Abbasi
  2012-04-27 16:23       ` Bill Findlay
  3 siblings, 0 replies; 31+ messages in thread
From: Nasser M. Abbasi @ 2012-04-27  4:19 UTC (permalink / raw)


On 04/26/2012 10:48 AM, Adam Beneschan wrote:
> On Wednesday, April 25, 2012 11:02:13 PM UTC-7, Okasu wrote:
>>  On 2012-04-26, Jeffrey Carter wrote:
>>  >
>>  >  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;
>>  >
>>
>>  It's a brain dead code.
>>  So you trying to say that i have to write loops for 10/100/1000d arrays
>>  by hand?
>


> I don't think I've *ever* seen an array with more than three dimensions ever used, in 35 years of programming.

me neither. I guess OP is working in the unified field theory area as 
one of the the string theories (M-theory) contains 11 dimensional 
space-time continuum for it to be correct. But 1000 dimensions is 
something I can not understand. May be a new theory is in the works?

>
> But I think Ada 2012 does support what you're looking for; see the
 >example at the bottom of 5.5.2 
(http://www.ada-auth.org/standards/12rm/html/RM-5-5-2.html).
>
>                      -- Adam

That is very interesting. I will definitely need to convert some Ada 
code I wrote that uses 2D grids for solving a PDE using this new 
construct to see better how it works. I hope GNAT supports this new 
feature, I will have to find out.

--Nasser



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27  1:58         ` Jerrid Kimball
@ 2012-04-27  7:39           ` Martin
  2012-04-27 18:08             ` Jeffrey Carter
  0 siblings, 1 reply; 31+ messages in thread
From: Martin @ 2012-04-27  7:39 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26  4:42 Can Ada iterate over Nd array? Okasu
                   ` (2 preceding siblings ...)
       [not found] ` <26754113.2767.1335431755764.JavaMail.geo-discussion-forums@vbki8>
@ 2012-04-27 11:09 ` Stephen Leake
  3 siblings, 0 replies; 31+ messages in thread
From: Stephen Leake @ 2012-04-27 11:09 UTC (permalink / raw)


Okasu <oka.sux@gmail.com> writes:

> 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?

Can you show an example of what you want in another language? 

I've never heard of such a thing being possible.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27  0:39       ` Randy Brukardt
@ 2012-04-27 13:30         ` Robert A Duff
  2012-04-28  8:24           ` Georg Bauhaus
  2012-05-01  2:02           ` Randy Brukardt
  0 siblings, 2 replies; 31+ messages in thread
From: Robert A Duff @ 2012-04-27 13:30 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> I have (or had) a five dimension array in one of my programs.

I'm curious what the purpose was.

>...It was quite a 
> problem to avoid running out of space (the size multiplies in a hurry!)

Yeah.  Which is why 1000 dimensions is ridiculous -- if the length
in each dimension is just 2, you have 2**1000 components.
I suppose you could have a 1x1x...x1 array.  Or if just one
'Length is 0, the whole thing is empty.  But those don't seem
terribly useful.

- Bob



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27  0:28     ` BrianG
@ 2012-04-27 13:46       ` Robert A Duff
  0 siblings, 0 replies; 31+ messages in thread
From: Robert A Duff @ 2012-04-27 13:46 UTC (permalink / raw)


BrianG <me@null.email> writes:

> If what is desired is an "n-dimensional array" (i.e. n is a parameter of
> some sort - generic or procedure parameter), what are you going to do
> with it, even if you can iterate?  How do you declare such a type?  If
> it's to be used as a library to work on "n-dimensional arrays", how do
> you specify subroutine parameters?  (Except as a raw memory address or
> equivalent.)

APL answers these questions (also J).  It's a rather different
language than Ada.  ;-)

- Bob



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27  0:36       ` Randy Brukardt
  2012-04-27  1:58         ` Jerrid Kimball
@ 2012-04-27 16:06         ` Shark8
  1 sibling, 0 replies; 31+ messages in thread
From: Shark8 @ 2012-04-27 16:06 UTC (permalink / raw)


On Thursday, April 26, 2012 7:36:10 PM UTC-5, Randy Brukardt wrote:
> 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.


Ok, that is really nice.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-26 15:48     ` Adam Beneschan
                         ` (2 preceding siblings ...)
  2012-04-27  4:19       ` Nasser M. Abbasi
@ 2012-04-27 16:23       ` Bill Findlay
  3 siblings, 0 replies; 31+ messages in thread
From: Bill Findlay @ 2012-04-27 16:23 UTC (permalink / raw)


On 26/04/2012 16:48, in article
393172.2032.1335455290715.JavaMail.geo-discussion-forums@yntt13, "Adam
Beneschan" <adam@irvine.com> wrote:

> I don't think I've *ever* seen an array with more than three dimensions ever
> used, in 35 years of programming.

From a Pascal compiler, written 36 years ago:

TYPE 
   CHECKRANGE   = (POSITIVE,NEGATIVE,POSORNEG) ;
VAR
   CHECKROUTINE : ARRAY [CHECKRANGE, (* +VE,-VE,OR EITHER *)
                         BOOLEAN,    (* OVERFLOW TEST NECESSARY *)
                         BOOLEAN,    (* MAX TEST NECESSARY *)
                         BOOLEAN,    (* MIN TEST NECESSARY *)
                         BOOLEAN     (* SIGN TEST NECESSARY *)
                        ] OF MONITORROUTINES;

I admit that it was noteworthy even then.

-- 
Bill Findlay
with blueyonder.co.uk;
use  surname & forename;





^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27  7:39           ` Martin
@ 2012-04-27 18:08             ` Jeffrey Carter
  2012-04-30  7:20               ` Martin
  0 siblings, 1 reply; 31+ messages in thread
From: Jeffrey Carter @ 2012-04-27 18:08 UTC (permalink / raw)


On 04/27/2012 12:39 AM, Martin wrote:
>     type A is array (1 .. 3) of Integer;
>     type B is array (1 .. 4) of A;
>     type C is array (1 .. 2) of B;

These are all 1-D arrays.

-- 
Jeff Carter
"We'll make Rock Ridge think it's a chicken
that got caught in a tractor's nuts!"
Blazing Saddles
87



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27 13:30         ` Robert A Duff
@ 2012-04-28  8:24           ` Georg Bauhaus
  2012-04-28  9:35             ` björn lundin
  2012-05-01  2:02           ` Randy Brukardt
  1 sibling, 1 reply; 31+ messages in thread
From: Georg Bauhaus @ 2012-04-28  8:24 UTC (permalink / raw)


On 27.04.12 15:30, Robert A Duff wrote:
> "Randy Brukardt"<randy@rrsoftware.com>  writes:
>
>> I have (or had) a five dimension array in one of my programs.
>
> I'm curious what the purpose was.

Just a guess: when the iteration does not compute
something from the index values themselves, then
it is brain dead having to put them there.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-28  8:24           ` Georg Bauhaus
@ 2012-04-28  9:35             ` björn lundin
       [not found]               ` <raadncdcv9V-hgHSnZ2dnUVZ_v2dnZ2d@earthlink.com>
  2012-04-30 14:48               ` gautier_niouzes
  0 siblings, 2 replies; 31+ messages in thread
From: björn lundin @ 2012-04-28  9:35 UTC (permalink / raw)


We use a 5 dimensional array for selecting locations
In our wms/wcs system.  Warehouse control system, that is. 
A location is described by a 5- coordinat system
Store
Rack
Stack
Level
Depth

This was designed around 1990 so today we might have used other
Techniques. Dbacces was slow then, 
--
Björn Lundin



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
       [not found]               ` <raadncdcv9V-hgHSnZ2dnUVZ_v2dnZ2d@earthlink.com>
@ 2012-04-28 23:19                 ` björn lundin
  0 siblings, 0 replies; 31+ messages in thread
From: björn lundin @ 2012-04-28 23:19 UTC (permalink / raw)


Usual values are
Stores: 2-5
Racks: 20
Stacks: 100
Level: 15
Depth: usually 1, sometimes 2, in rare cases up to 12
So, not that many, a large project may have up two 100_000 locations
Physical pallet locations that is. 
The values of course varies with projects. 

Yes, it could be mapped somehow, but this 

Loc : location_type renames stores(2,4,7,4,1) 

notation makes it readable. 
And loops for finding free locations are fast. They had to be in ram, since the location should be chosen
At a selection point on the conveyor system, without the pallet stopping. That meant
* conveyor send 'pallet at selection location'
* location selection
* send new destination to conveyor

This had to be fast, serial lines was used, and databases were not that fast. 
--
Björn lundin



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27 18:08             ` Jeffrey Carter
@ 2012-04-30  7:20               ` Martin
  2012-04-30 13:21                 ` Robert A Duff
  0 siblings, 1 reply; 31+ messages in thread
From: Martin @ 2012-04-30  7:20 UTC (permalink / raw)


On Friday, April 27, 2012 7:08:15 PM UTC+1, Jeffrey Carter wrote:
> On 04/27/2012 12:39 AM, Martin wrote:
> >     type A is array (1 .. 3) of Integer;
> >     type B is array (1 .. 4) of A;
> >     type C is array (1 .. 2) of B;
> 
> These are all 1-D arrays.
> 
> -- 
> Jeff Carter
> "We'll make Rock Ridge think it's a chicken
> that got caught in a tractor's nuts!"
> Blazing Saddles
> 87

True but a 3-d array can always be re-arranged into 3 * 1-d arrays.

Is there an underlying difference between the 2 styles? Can a 'genuine' multi-dimensionsal array be implemented more efficiently?
-- Martin



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-30  7:20               ` Martin
@ 2012-04-30 13:21                 ` Robert A Duff
  2012-04-30 15:42                   ` Martin
  0 siblings, 1 reply; 31+ messages in thread
From: Robert A Duff @ 2012-04-30 13:21 UTC (permalink / raw)


Martin <martin@thedowies.com> writes:

> True but a 3-d array can always be re-arranged into 3 * 1-d arrays.

That's true if the bounds are fixed, or all but the outermost one are
fixed.  But a two-dimensional array can have "range <>" in both
dimensions, which is impossible (in Ada) for an array of array.

- Bob



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-28  9:35             ` björn lundin
       [not found]               ` <raadncdcv9V-hgHSnZ2dnUVZ_v2dnZ2d@earthlink.com>
@ 2012-04-30 14:48               ` gautier_niouzes
  1 sibling, 0 replies; 31+ messages in thread
From: gautier_niouzes @ 2012-04-30 14:48 UTC (permalink / raw)


Am Samstag, 28. April 2012 11:35:49 UTC+2 schrieb björn lundin:
> We use a 5 dimensional array for selecting locations
> In our wms/wcs system.  Warehouse control system, that is. 
> A location is described by a 5- coordinat system
> Store
> Rack
> Stack
> Level
> Depth
> 
> This was designed around 1990 so today we might have used other
> Techniques. Dbacces was slow then, 
> --
> Björn Lundin

Sounds familiar (mutatis mutandis)... Here is:

  type Aggregator is record
    loc              : Locator_String;
    [ some other data ]
  end record;

  type Aggregator_array is array(Integer range <>) of Aggregator;

  type Aggregator_stack(max: Natural) is record
    top : Natural:= 0;
    item: Aggregator_array(1..max);
  end record;

  type Monster is
        array(Coverage_type,
              Risk_type,
              Struct_mod_type)
  of
        Aggregator_stack(max);

from a tool which is used to compact data - without loss of important information, of course :-).
Each cell, agg(cov,ris,smo).item(idx) is of type Aggregator... 
The first 3 index types are short enumerated types.

G.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-30 13:21                 ` Robert A Duff
@ 2012-04-30 15:42                   ` Martin
  0 siblings, 0 replies; 31+ messages in thread
From: Martin @ 2012-04-30 15:42 UTC (permalink / raw)


On Monday, April 30, 2012 2:21:58 PM UTC+1, Robert A Duff wrote:
> Martin <martin@...com> writes:
> 
> > True but a 3-d array can always be re-arranged into 3 * 1-d arrays.
> 
> That's true if the bounds are fixed, or all but the outermost one are
> fixed.  But a two-dimensional array can have "range <>" in both
> dimensions, which is impossible (in Ada) for an array of array.
> 
> - Bob

Ah, ok. I don't think I've run into that - my world is usually very bounded ;-)
Cheers
-- Martin



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Can Ada iterate over Nd array?
  2012-04-27 13:30         ` Robert A Duff
  2012-04-28  8:24           ` Georg Bauhaus
@ 2012-05-01  2:02           ` Randy Brukardt
  1 sibling, 0 replies; 31+ messages in thread
From: Randy Brukardt @ 2012-05-01  2:02 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wccsjfpl2tt.fsf@shell01.TheWorld.com...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> I have (or had) a five dimension array in one of my programs.
>
> I'm curious what the purpose was.

I think it held the results of a simulation where 5 parameters were varied 
small amounts from the starting point. But I admit I don't remember what I 
did with the results afterwards.

                                  Randy.





^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2012-05-01  2:02 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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