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

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.

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?

1 Like

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

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:

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
      Result : Array_Str (First_Low .. First_High, Second_Low .. Second_High);
      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;

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!

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