Oxygene: 2D Arrays

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.
Thanks,
–tex

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;
begin
  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]]]
    ];
  
  writeLn(data[1,1,1,1]);
  assert(data[1,1,1,1] = 15);
  readLn;
end;

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?
:thinking:

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

would your var x not be an arrary so that x[0] = 1 & x[1]=2?
In which case your an : array[0…1] of (integer, integer) could be used as:
an[0, 0] = 1st integer in first tuple &
an[0, 1] = 2nd integer in 1st tuple?

OR would a Oxygene “tuple” be equivalent to Delphi TPoint, addressed with “X” & “Y” 's?

I’ve never used such vars other than TPoint in Delphi for which TPoint.X = 1st, & TPoint.& the 2nd of a tuple.

While conceptually similar (especially when talking literals), arrays and tuples ar every different, would not have the necessarily have the same in-memory structure, and not be assignment compatible.

See https://docs.elementscompiler.com/Oxygene/Types/Tuples/ for more min tuples.

Sure, either an array or a tuple x could be accessed the same way, with x[0] and x[1] in this case, but the similarities end there.

Thanks, Marc. Tuples look useful to me & I would not have thought about 'em as Delphi did not have them that I know of.

For what it’s worth; the () syntax is ONLY valid inside const/var declaration.

1 Like

3 posts were split to a new topic: Fun with Tuples