New Issue: Should the operators '#' 'by' 'align' be promotable?

19348, "vasslitvinov", "Should the operators '#' 'by' 'align' be promotable?", "2022-03-03T01:49:48Z"

Currently the operators # by align work on a range or rectangular domains and a suitable index. # also works on rectangular arrays.

What should the behavior be when they are invoked on something else? The following two policies are easier to implement:

  • (S) Issue a "specialized" error clearly stating that this use is currently not supported.
  • (U) Treat them like a user-defined function would be treated. Namely:
    • attempt to apply promotion, then
    • issue a "generic" error saying "unresolved call, there are NN candidates"

What behavior do we want - (S) or (U) or something else?

I see this as a tradeoff between:

  • elegance -- fewer special cases, more uniform availability of promotion, vs.
  • ease of understanding the program behavior -- promotion can be subtle and unexpected to beginners.

I am raising this question because our implementation looks inconsistent. For example:

var arrayOfRanges: [1..11] range = 1..9;
iter iterOfRanges() { yield 1..9; yield 11..19; }

writeln(6 # 7);               // generic error
writeln(arrayOfRanges # 7);   // array #, prints 1..9 1..9 1..9 1..9 1..9 1..9 1..9
writeln(iterOfRanges() # 7);  // promoted #, prints 1..7 11..17

writeln(6 by 7);              // specific error
writeln(arrayOfRanges by 7);  // specific error
writeln(iterOfRanges() by 7); // specific error

The current implementation is more consistent in disallowing promotion over the second argument and reporting a specific error instead, which may or may not be the desired behavior.

This question may apply to other operators as well, ex. #19254, #19264, #19332. Somewhat related: #19261.