Chapel: Automatic Domain Map
This is one of the coolest things I’ve discovered in a programming language in a long time. It’s not an algorithmic revolution in AI or anything. But it did make me do a double take. Automatic domain mapping is the idea where if you have a function designed to take an input, it can be sent a range of inputs instead and the machinery of Chapel just knows what to do!
Let F be a function that takes an integer and does some transformation then returns the result. Let R be a range of integers. Let G be the result of mapping F over all values in R.
Code:
// File: domain_map.chpl proc main() { proc F(i: int) return i + 10; const R = 0..10; const G = F(R); writeln(G); }
Compilation:
$ chpl domain_map.chpl -o domain_map
Invocation:
$ ./domain_map
Output:
10 11 12 13 14 15 16 17 18 19 20