Inconsistent array constructors

Skybuck Flying <[email protected]> Sun, 15 Jan 2023 14:09:30 -0800 (PST)
Newsgroups alt.comp.lang.borland-delphi
Message-ID <[email protected]>
The [1,2,3 ]
in
vSomething := [ 1, 2, 3 ];
or
SomeProcedure( [1,2,3] );

Can mean different things depending on:

1. If it's a dynamic array
Thinks it's an array.
2. If it's a open array parameter
2.1 Inside the function
Thinks it's a set.
vs
2.2 Outside the function
Thinks it's an array.
2.3 Using it inside open array function not allowed...

2.1 is inconsistent with rest of language design.

Little bit fuzzy/messy example but it illustrates it:

// helper routine, example:
// FillArray( Values, [ 1, 2, 3] );
procedure FillArray( var VarValues : array of integer; const ConstValues : array of integer );
var
	vIndex : integer;
begin
	for vIndex := 0 to Length(ConstValues)-1 do
	begin
		VarValues[vIndex] := ConstValues[vIndex];
	end;
end;

procedure FillWithLethalInternetValuesV2( var Values : array of integer );
var
	vArray : array of integer;
begin
	// strangely enough Delphi thinks this is a set !?! LOL WTF. maybe because 1,2,3 is part of an integer set ?
	Values := [ 1, 2, 3 ]; // Problem with Delphi language, Delphi thinks it's a SET instead of an ARRAY ?!?!

	// ^ inconsistent design between open array parameters and sets...
	FillArray( Values, [ 1, 2, 3] ); // open array parameter, also known as open array constructor syntax.

	// even more confusing is that nowadays dynamic array constructors are also possible:
	vArray := [ 1, 2, 3 ];
end;

Bye for now,
  Skybuck.