I've been trying out Chapel off and on over the past year or so. I have used C and C++ briefly in the past, but most of my experience is with dynamic languages such as Python, Ruby, and Erlang more recently.
After some exposure to Erlang and its function clauses, I was excited to find out about where clauses in Chapel. However, I've run into a barrier with their use. Learn Chapel in Y minutes contains the following code demonstrating a use of the where clause:
proc whereProc(param N : int): void
where (N > 0) {
writeln("N is greater than 0");
}
proc whereProc(param N : int): void
where (N < 0) {
writeln("N is less than 0");
}
whereProc(10);
whereProc(-1);
This produces the expected output for each of the two scalar values, 10 and -1. However, I have tried to write similar programs that iterate over a range or an array. I've even tried recursion. In all cases I get essentially the same error:
whereproc2.chpl:12: error: unresolved call 'whereProc(int(64))'
whereproc2.chpl:1: note: candidates are: whereProc(param N: int)
whereproc2.chpl:6: note: whereProc(param N: int)
The code that produced this particular error is:
proc whereProc(param N : int): void
where (N > 0) {
writeln("N is greater than 0");
}
proc whereProc(param N : int): void
where (N <= 0) {
writeln("N is less than or equal to 0");
}
for n in 1..10 do
whereProc(n);
Is there something I'm missing that will cause this to work, or is this not expected to work? I noticed that on Learn Chapel in Y minutes it says all information needs to be known at compile time. Are the contents of a finite range or initialized array not known at compile time? It seems to me that the usefulness of the where clause is limited if it only works with scalar values.