[Ada] How do I implement and work with multi-dimensional arrays or matrices in Ada?

In Ada, multi-dimensional arrays or matrices can be implemented using nested arrays. Here's an example of how to declare, initialize, and access elements of a two-dimensional array in Ada:

 1with Ada.Text_IO; use Ada.Text_IO;
 2
 3procedure MultiDimensionalArray is
 4   -- Declare a 2D array of integers
 5   type Matrix is array (Positive range <>, Positive range <>) of Integer;
 6
 7   -- Declare and initialize a 2D array
 8   matrix : Matrix := ((1, 2, 3),
 9                       (4, 5, 6),
10                       (7, 8, 9));
11
12begin
13   -- Accessing and printing elements of the matrix
14   Put_Line("Element at (2, 2): " & Integer'Image(matrix(2, 2))); -- Output: 5
15
16   -- Modifying an element of the matrix
17   matrix(3, 1) := 10;
18
19   Put_Line("Updated element at (3, 1): " & Integer'Image(matrix(3, 1))); -- Output: 10
20end MultiDimensionalArray;

In this example, we define a type Matrix as an array of integers with dynamic ranges for both dimensions. We then initialize the matrix with the desired values using the aggregate notation.

To access elements of the matrix, use the syntax matrix(row_index, column_index).

To modify an element, simply assign a new value to the desired array element.

Note that Ada is a strongly typed language, so you need to ensure that the types of elements you access or assign are compatible with the array type.