The code below compiles and runs nicely (Chapel 2.5), and does what it is meant to.
However, if I uncomment the three procedures meant to include assignment to real, compilation fails with the message
overeq.chpl:35: In function 'main':
overeq.chpl:49: error: an init= initializing 'narray(1)' from 'narray(1)' is missing
overeq.chpl:1: note: expected because assignment is defined here between these two types
Any hints of how to uncomment and make the original code work will be welcome. Thanks.
record narray {
param ran = 1; // the rank
var dom: domain(ran) = {1..1}; // the domain
var arr: [dom] real = 0.0; // the array
proc size: int { // the size of a narray
return dom.size;
}
inline proc ref this(in k: int...?n) ref { // access arr[k]
return arr[k];
}
iter ref these() ref { // iterate over the whole narray
for i in dom do {
yield arr[i];
}
}
iter ref these( // iterate over several ranges
in rak: range(int)...?r
) ref {
for k in zip(rak) do {
yield arr[k];
}
}
/*
proc init=(const in a: real) {
this.arr = a;
}
operator :(a: real, type t: narray) {
var v: narray = a;
return v;
}
operator =(ref lhs: narray, const in a: real) {
lhs.arr = a;
}
*/
}
proc main() {
writeln(isGeneric(narray));
writeln(isGeneric(narray(1)));
var a: narray(2);
var b: narray(1);
var c: narray(1);
var z: [1..5] narray(1);
a = new narray(2,{1..10,1..5});
b = new narray(1,{1..10});
c = new narray(1,{1..3});
writeln(a);
writeln(b);
writeln(c);
for i in 1..5 do {
z[i] = new narray(1,{1..i});
z[i].arr = 1..i ;
}
for i in 1..5 do {
writeln(z[i]);
}
}