comp.lang.ada
 help / color / mirror / Atom feed
* Ada question (defining types)
@ 2000-08-17  0:00 Reinert Korsnes
  2000-08-17  0:00 ` Aaro Koskinen
  2000-08-18  0:00 ` Dr. Joachim Schr�er
  0 siblings, 2 replies; 4+ messages in thread
From: Reinert Korsnes @ 2000-08-17  0:00 UTC (permalink / raw)


Hi, I am still a bit new on Ada:

Is it possible to make the following more compact and relyable
(less typo/error prone):


 Longs : constant array ( Long_I ) of Integer :=
             (  0,  5, 10, 15, 20, 25, 30, 35, 40, 45, 50,
                       55, 60, 65, 70, 75, 80, 85, 90, 95,
              100,105,110,115,120,125,130,135,140,145,150,
                      155,160,165,170,175,180,185,190,195,
              200,205,210,215,220,225,230,235,240,245,250,
                      255,260,265,270,275,280,285,290,295,
              300,305,310,315,320,325,330,335,340,345,350,355);

?

I believe this is a clumsy construct...

reinert

-- 
Norwegian Polar Institute
Polar Environment Center
N-9296 Tromso
Norway
Fax: +47 77750501

http://geophys.npolar.no/~reinert/personal.html




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

* Re: Ada question (defining types)
  2000-08-17  0:00 Ada question (defining types) Reinert Korsnes
@ 2000-08-17  0:00 ` Aaro Koskinen
  2000-08-17  0:00   ` Ian Clifton
  2000-08-18  0:00 ` Dr. Joachim Schr�er
  1 sibling, 1 reply; 4+ messages in thread
From: Aaro Koskinen @ 2000-08-17  0:00 UTC (permalink / raw)


reinert@ola.npolar.no (Reinert Korsnes) writes:
> Is it possible to make the following more compact and relyable
> (less typo/error prone):
[...]
>  Longs : constant array ( Long_I ) of Integer :=
>              (  0,  5, 10, 15, 20, 25, 30, 35, 40, 45, 50,
[...]
>               300,305,310,315,320,325,330,335,340,345,350,355);

Implement it using a function instead of an array.

-- 
Aaro Koskinen, aaro@iki.fi, http://www.iki.fi/aaro




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

* Re: Ada question (defining types)
  2000-08-17  0:00 ` Aaro Koskinen
@ 2000-08-17  0:00   ` Ian Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Clifton @ 2000-08-17  0:00 UTC (permalink / raw)


>>>>> "Aaro" == Aaro Koskinen <aaro@iki.fi> writes:

    reinert@ola.npolar.no (Reinert Korsnes) writes:
    >> Is it possible to make the following more compact and relyable
    >> (less typo/error prone):
    >> Longs : constant array ( Long_I ) of Integer := ( 0, 5, 10, 15,
    >> 20, 25, 30, 35, 40, 45, 50,
    >> 300,305,310,315,320,325,330,335,340,345,350,355);

    Aaro> Implement it using a function instead of an array.

Yes, I think this is the most natural way of doing it in Ada. 

If for some reason you really want the constant array, there's no
`implied do' construct in Ada's `array aggregate' array constructor as
there is in Fortran95 (I suspect this might be the feature Reinert is
missing). You could however initialize your constant array with an
array-valued generator function (which would in effect be an Ada-style
wrapper for such an `implied do').

-- 
Ian Clifton                   Phone: +44 1865 275631
Dyson Perrins Laboratory      Fax:   +44 1865 275674
Oxford University  OX1 3QY UK ian.clifton@linacre.ox.ac.uk




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

* Re: Ada question (defining types)
  2000-08-17  0:00 Ada question (defining types) Reinert Korsnes
  2000-08-17  0:00 ` Aaro Koskinen
@ 2000-08-18  0:00 ` Dr. Joachim Schr�er
  1 sibling, 0 replies; 4+ messages in thread
From: Dr. Joachim Schr�er @ 2000-08-18  0:00 UTC (permalink / raw)


Hello,

a possible solution using a function could be as follows:
---------------------------------------------
with ada.text_io; use ada.text_io;
procedure testlongs is

  type integer_array is array(positive range <>) of integer;

  function The_integer_array(length  : in positive;
                             spacing : in integer) return integer_array is
    the : integer_array(1 .. length);
  begin
    for i in the'range loop
      the(i) := (i - 1) * spacing;
    end loop;
    return the;
  end The_integer_array;

  longs : constant integer_array :=
             The_integer_array(length => 355/5+1, spacing => 5);
begin
  for i in longs'range loop
    put(integer'image(longs(i)));
  end loop;
end;
------------------------------------------------------------------
Reinert Korsnes <reinert@ola.npolar.no> schrieb in im Newsbeitrag:
8ngoog$f5e$1@news.uit.no...
> Hi, I am still a bit new on Ada:
>
> Is it possible to make the following more compact and relyable
> (less typo/error prone):
>
>
>  Longs : constant array ( Long_I ) of Integer :=
>              (  0,  5, 10, 15, 20, 25, 30, 35, 40, 45, 50,
>                        55, 60, 65, 70, 75, 80, 85, 90, 95,
>               100,105,110,115,120,125,130,135,140,145,150,
>                       155,160,165,170,175,180,185,190,195,
>               200,205,210,215,220,225,230,235,240,245,250,
>                       255,260,265,270,275,280,285,290,295,
>               300,305,310,315,320,325,330,335,340,345,350,355);
>
> ?
>
> I believe this is a clumsy construct...
>
> reinert
>
> --
> Norwegian Polar Institute
> Polar Environment Center
> N-9296 Tromso
> Norway
> Fax: +47 77750501
>
> http://geophys.npolar.no/~reinert/personal.html






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

end of thread, other threads:[~2000-08-18  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-17  0:00 Ada question (defining types) Reinert Korsnes
2000-08-17  0:00 ` Aaro Koskinen
2000-08-17  0:00   ` Ian Clifton
2000-08-18  0:00 ` Dr. Joachim Schr�er

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