chapel
chapel copied to clipboard
[Feature Request]: Add homogeneous value assignment for tuples.
Summary of Feature
Description:
Wanting to assign a value to every index in a tuple.
var x: 4 * int = 0; // can't do this :(
Is this issue currently blocking your progress?
No, just workarounds.
Solution?
inline operator =(ref tup: _tuple, v: tup(0).type) where isHomogeneousTuple(tup) {
for param i in 0..<tup.size do
tup(i) = v;
}
It seems like this method isn't being picked up. Maybe the failure needs to be lifted by the compiler?
inline operator =(ref tup: _tuple, v: tup(0).type) where isHomogeneousTuple(tup) {
for param i in 0..<tup.size do
tup(i) = v;
}
var x: 4 * int;
x = 2;
writeln(x);
// ...: error: cannot initialize 'x' of type '4*int(64)' from '2'
It seems like this method isn't being picked up.
@Iainmon : I think that this is because the x=2 is being interpreted as an initialization (e.g., init= routine) rather than an assignment, which is what you've defined here. Note that this is a case where the compiler applies "split initialization" to treat the first assignment as an initialization since there are no intervening references to 'x' or control flow statements that would make it not be treated as such.
Testing this theory by adding an explicit initialization of x seems to confirm this, but runs into a new / different problem ATO:
inline operator =(ref tup: _tuple, v: tup(0).type) where isHomogeneousTuple(tup) {
for param i in 0..<tup.size do
tup(i) = v;
}
var x: 4 * int = (0,0,0,0);
x = 2;
writeln(x);
error: unsupported = overload to '4*int(64)' from 'int(64)'
note: assignment overloads setting array or tuples are not currently supported