The error you are seeing is about the line:
elements[i] = 'nil';
'nil'
is a string, not the nil value, which is written as just nil
without any quotes. Assigning a string to a slot in an array of int(64) doesn't work, so the compiler issues an error.
In Chapel only classes can have a nil value though, so you'll need to use a different way to keep track of which positions in the elements
array are filled.
One way to do that would be to add two new integers to your class that keep track of the first and last positions containing valid values. As you add values to the queue the last
position increases, and as you remove values the first
position increases. When either of those values passes the end of the array, it wraps around back to the front. If last
ever catches first
, then the array is full. If first
ever catches last
then the array is empty.
A few other things I think should be corrected in your code are:
use semaphore.chpl;
Use statements work with module names, not filenames, so this should probably be use semaphore;
.
If I'm understanding your intent here, this code is trying to set the size of the elements
array to 5.
var elementsDomain: domain(1);
var elements: [elementsDomain] eltType = 5;
The array's domain controls the size of the array, so the way to set the array size is through the domain:
var elementsDomain: domain(1) = {0..#5};
var elements: [elementsDomain] eltType;
elementsDomain = (0..capacity - 1);
is setting elementsDomain
to a range literal value. This works since the domain is 1-dimensional, but to make it more clear, you can set it to a domain literal value instead: {0..capacity - 1}
.