# How to program this array setup in Ada 95 please for .ads and .adb files

**URL:** <https://forum.ada-lang.io/t/how-to-program-this-array-setup-in-ada-95-please-for-ads-and-adb-files/969>\
**Category:** General\
**Created:** [July 7, 2024, 9:06pm UTC](https://forum.ada-lang.io/t/how-to-program-this-array-setup-in-ada-95-please-for-ads-and-adb-files/969 "2024-07-07T21:06:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![m8vl4](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@m8vl4](https://forum.ada-lang.io/u/m8vl4)\
**Post date:** [July 7, 2024, 9:06pm UTC](https://forum.ada-lang.io/t/how-to-program-this-array-setup-in-ada-95-please-for-ads-and-adb-files/969/1 "2024-07-07T21:06:11Z")

</div>

DIM array\_str$( idx1 TO idx2, jdx1 TO jdx2), in TB  
– two dimensions indexed respectively as ( idx1 … idx2), ( jdx1 … jdx2)  
Require a FUNCTION with input of idx1, idx2, jdx1, and jdx2 to return  
the setup array\_str$( 1…2, 1…3) from plug’n’chug of LET idx1, idx2, jdx1, jdx2 = 1, 2, 1, 3  
The string type is unbounded\_string, obviously.

---

<div class="post-metadata">

**Author:** ![JeremyGrosser](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/jeremygrosser/32/3_2.png) [@JeremyGrosser](https://forum.ada-lang.io/u/JeremyGrosser)\
**Post date:** [July 7, 2024, 9:56pm UTC](https://forum.ada-lang.io/t/how-to-program-this-array-setup-in-ada-95-please-for-ads-and-adb-files/969/2 "2024-07-07T21:56:54Z")

</div>

This sounds like a homework problem out of context. It seems unethical to simply give you the solution, but maybe we can provide clues if you tell us what you’ve tried and where you’re stuck?

---

<div class="post-metadata">

**Author:** ![leo-brewin](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/leo-brewin/32/175_2.png) [@leo-brewin](https://forum.ada-lang.io/u/leo-brewin)\
**Post date:** [July 7, 2024, 11:08pm UTC](https://forum.ada-lang.io/t/how-to-program-this-array-setup-in-ada-95-please-for-ads-and-adb-files/969/4 "2024-07-07T23:08:44Z")

</div>

A little tip – please don’t insult people trying to help you. They’ve given their time to offer help. Be kind.

---

<div class="post-metadata">

**Author:** ![simonjwright](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/simonjwright/32/11_2.png) [@simonjwright](https://forum.ada-lang.io/u/simonjwright)\
**Post date:** [July 8, 2024, 1:49pm UTC](https://forum.ada-lang.io/t/how-to-program-this-array-setup-in-ada-95-please-for-ads-and-adb-files/969/7 "2024-07-08T13:49:02Z")

</div>

I don’t think that GNAT’s `pragma Ada_95;` is a total guarantee that only Ada 95 syntax and semantics apply, but try this:

```ada
pragma Ada_95;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
procedure M8v14 is
   type Array_Str
     is array (Positive range <>, Positive range <>) of Unbounded_String;
   function Slicer (Input : Array_Str;
                    First_Low, First_High : Positive;
                    Second_Low, Second_High : Positive)
                   return Array_Str
   is
      Result : Array_Str (First_Low .. First_High, Second_Low .. Second_High);
   begin
      for First in Result'Range (1) loop
         for Second in Result'Range (2) loop
            Result (First, Second) := Input (First, Second);
         end loop;
      end loop;
      return Result;
   end Slicer;
...

```

---

<div class="post-metadata">

**Author:** ![simonjwright](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/simonjwright/32/11_2.png) [@simonjwright](https://forum.ada-lang.io/u/simonjwright)\
**Post date:** [July 8, 2024, 7:26pm UTC](https://forum.ada-lang.io/t/how-to-program-this-array-setup-in-ada-95-please-for-ads-and-adb-files/969/11 "2024-07-08T19:26:52Z")

</div>

The declaration of `Result` really just sets up the proper bounds; the values contained are undefined. The point of the nested iterations is to set the values in `Result` to the required values from `Input`.

If you were dealing with a one-dimensional array you could use a slice (`Arr (1 .. 3)`) but I’m pretty sure there’s no equivalent for arrays of \>1 dimension. If I’m wrong, someone please tell us so!

```ada
14. return Input (First_Low .. First_High, Second_Low .. Second_High);
                                               |
    >>> error: slice cannot have more than one dimension

```
