How to pass a constant matrix as an argument to a procedure call

I want to check multiple matrices using a procedure. Each matrix must be transmitted as a matrix, for example:

type TMatrix = array of array of integer; procedure test_kernel (mat: TMatrix); .... test_kernel ([[1, 2], [1, 3]]); // <== does not compile 

I cannot find the correct syntax to do this correctly (using parentheses). Does anyone know how to pass a constant matrix as an argument to a procedure? Is it possible at all?

EDIT

As I do not want, I decided to use:

 type TMatrix = array of integer; procedure test_kernel (rows, cols: integer; mat: TMatrix); .... test_kernel (2, 2, [1, 2, 1, 3]); 

So, I get the illusion and readability of the matrices. Thanks everyone!

+4
source share
2 answers

In fact, you can do this if you use a slightly different TMatrix declaration, but IMHO does not increase the readability of the code:

 type TVector = array of integer; TMatrix = array of TVector; procedure test_kernel (mat: TMatrix); .... test_kernel(TMatrix.Create(TVector.Create(1, 2), TVector.Create(1, 3))); 
+4
source

You cannot do what you want with constants or open arrays. TMatrix is a dynamic array, and you cannot have constants that are dynamic arrays. And the matrix is ​​2D, but open arrays cannot be nested. You cannot have an open array of open arrays. If it were only a vector, i.e. One size, then you could use open arrays. However, since you have a 2D matrix, open arrays cannot help.

You will need to use a variable that is initialized at runtime. You can do this fairly easily in the initialization section if you really have a constant.

+2
source

Source: https://habr.com/ru/post/1384563/


All Articles