Hello! The following code compiles and runs without errors:
var towsons: domain(string);
towsons = {"red","green","yellow","blue"};
var woff: [towsons] real;
woff["red"] = 1.0;
woff["green"] = 2.0;
woff["yellow"] = 3.0;
woff["blue"] = 4.0;
planrot(woff); // Why does chapel allow this?
writeln("-"*20);
planrot(woff["blue"]); // This should be ok
proc planrot(in woff: real) {
writeln(woff);
}
But to me it does not make sense, and I would expect that the first call ("planrot(woff)") should trigger a compilation error... Could someone explain me why it does not? It looks like the same thing as sin(array) returning a whole array of sines, but planrot does not return anything ...
If you want to prevent promoting an array for a particular function you could have an overload that takes an array and produces a compiler error when that case resolves. So something like this:
proc foo(x : [] real) do
compilerError('foo may not be used for promotion');
proc foo(x : real) do
writeln(x);
var A : [0..10] real;
foo(A); // will resolve to version of function that errors
If that feels too burdensome, I think it would be reasonable to make a
feature request for an attribute that squashes that for you, e.g.
something like @noPromotionAllowed or something that could be attached
to functions.
Hi Lydia; thanks, but I don't think it is necessary. Promotion is a very
nice feature,
and I should have been more aware of it by now. Andy's solution works well
for me.