In the following code, I'm trying to get the 1st and 2nd rows of array A
by using either var
or ref
. Here, my understanding is that var
always creates a new array, while ref
creates an alias (or reference) to the right-hand side.
var A: [1..2, 1..3] int;
A = 0;
var row1 = A[ 1, .. ];
ref row2 = A[ 2, .. ];
row1 = 10;
row2 = 20;
writeln( "row1 = ", row1 );
writeln( "row2 = ", row2 );
writeln( "A = ", A );
The result is as expected (i.e., the 1st row of A
is not modified):
row1 = 10 10 10
row2 = 20 20 20
A = 0 0 0
20 20 20
But if I print the type of row1
and row2
writeln( "row1.type = ", row1.type: string );
writeln( "row2.type = ", row2.type: string );
I get this result:
row1.type = [ArrayViewRankChangeDom(1,int(64),false,2*bool,2*int(64),ArrayViewRankChangeDist(DefaultDist,2*bool,2*int(64)))] int(64)
row2.type = [ArrayViewRankChangeDom(1,int(64),false,2*bool,2*int(64),ArrayViewRankChangeDist(DefaultDist,2*bool,2*int(64)))] int(64)
This is somewhat surprising because I assumed row1
to be a "usual" array (i.e., not an alias). For example, the following vec
(which I call a "usual" array)
var vec: [1..3] int;
writeln( "vec.type = ", vec.type: string );
gives
vec.type = [domain(1,int(64),false)] int(64)
So I'm wondering whether there is some difference between row1
and vec
(as array types)...?