0

So I have a chapel issue i can't seem to figure out. I have a queue that one can set size. The only thing is is that it's setting size and filling the queue with a bunch of 0s (which make's sense). I'm trying to fill the queue with null rather than numerical values so later on when I work on the add method I can check if queue is null. I have attached an image of how everything is set up. Let me know if you guys have any guidance or ideas. The error that i'm getting is:

error: type mismatch in assignment from string to int(64)

I must be doing it the wrong way here.

enter image description here

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
insta catering
  • 151
  • 2
  • 12

1 Answers1

4

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}.

David Iten
  • 545
  • 1
  • 3
  • 10