Oxygene: 2D Arrays

Cannot access 2nd Col of 2D Array? Code:

//Global Constant Data
xDis = 0; //Displayed, Short
xDes = 1; //Full Descripton
sStructure : Array[0…1, xDis…xDes] of String = (
(‘CMU’, ‘Concrete Block Wall’),
(‘Concrete’, ‘Poured Concrete Wall’));

method WTF;
Console.Write('sStructure[0, 0]= ’ + sStructure[0, 0]); //*** outputs correctly: ‘CMU’;
Console.Write('sStructure[0, 1]= ’ + sStructure[0, 1]); //*** BLANK OUTPUT *** WTF???

Chrome Console Output
sStructure[0, 0]= CMU
sStructure[0, 1]=

It worked after initializing 2nd Col in a Method (see below) which means it is an initialization problem.

How do I initialize constant 2, 3, 4D arrays?

method WTF;
sStructure[0, 1] := ‘Concrete Block Wall’;
sStructure[1, 1] := ‘Poured Concrete Wall’;
Console.Write('sStructure[0, 0]= ’ + sStructure[0, 0]); //*** outputs correctly: ‘CMU’;
Console.Write('sStructure[0, 1]= ’ + sStructure[0, 1]); //*** outputs correctly, BUT required programed initialization??? ***

Seems an initialization issue to me too. I can replicate it on Island/Windows.ConsoleApplication.7z (1.7 KB)

Thanks. I’ve played around some, but the only working soln I’ve found is to give up on 2D Arrays & only use 1D arrays & then map my 2D In-my-mind array to a 1D Array, e.g.

Map2D(nRow, nCol : Integer) : Integer;
result := 2*nRow + nCol;

Don’t like it cuz I’m converting a large Delphi Ap to WASM & it has several 2D tables along with a couple of LARGE 4D tables in constant values.

Maybe we should ping @ck?
it is also important for me since I need to initialize in a lot of multidimensional data for tensor flow applications

Carlo will know better, tomorrow, but this does seem like a bug, yes. What platform?

Water, Oxygene, WASM

and Island/Windows, at least.

Thanks, logged as bugs://83833

Logged. This certainly looks like a bug yes. I’ll look into it.

bugs://83833 got closed with status fixed.

Sorry for maybe dumb query (I’m a newbie), but how do I get the bug-fixed version? I’m programming now using multidimensional arrays. I clicked “check for updates” on Water & it said I was up to date.

It’ll be in next Friday’s update

Thanks, guys. I assume the fix will work for any dimensional arrays, e.g. 4D, which I use? Also, I’ve always used “(data )” & saw others use brackets “[data]” for arrays. Is there any reason to use “()” or “[]”?

1 Like

It seems that the fix will work for at least 4D arrays - the following code runs as expected. I am very happy with that! It allows me to “naturally” initialize vectors, matrices and high dimensional tensors.

class method Main(args: array of String): Int32;
  const data: array[0..1, 0..1, 0..1, 0..1] of Integer = 
      [ [[0, 1],[2,3] ], [[4,5],[6,7]]], 
      [ [[8,9],[10,11]], [[12,13],[14,15]]]
  assert(data[1,1,1,1] = 15);

I personally think using brackets [ ] for matrices and vectors, are very “mathematically native” (similar to Python), and easier to initialize vector and matrix constants.

I don’t believe () is valid fir array literals in Pascal, Oxygene or otherwise?

But … it does indeed get compiled and running, in Oxygene?

I’ve used Delphi for decades & always used paren’s “()” for all arrays of all types & have several such existing in a Delphi Windows Ap that I’m coverting to a WASM, Oxygene Ap. The “()” seem to work; however, I don’t know if oxygene will cause me trouble in the future if “[]” is the preferred way. I hope not.

Carlo tells me we support () in Delphi Compatibility (not a mode I user myself), so that would explain that. If the is the case, support for the syntax won’t go away, no — though I could imaging scenarios where it might be ambiguous, when relying on type inference, eg is:

var x :=(1,2)

an array[0..1] of Integer or a tuple of (Integer, Integer)?

1 Like