Error: domain slice requires a range in at least one dimension

Hello,

This code fails to compile (version 1.32), emitting the error in the subject:

var charges : string = "Charges :\
 core                        :    12.00000000    \
 valence                     :    78.00000000    \
 interstitial                :    19.49404901    \
 muffin-tins (core leakage)\
  species :    1 (Si)\
   atom    1                 :    10.99038246     (   0.000000000    )\
   atom    2                 :    10.99038246     (   0.000000000    )\
   atom    3                 :    10.99038246     (   0.000000000    )\
  species :    2 (O)\
   atom    1                 :    6.255800601     (  0.1372672035E-04)\
   atom    2                 :    6.255800601     (  0.1372672035E-04)\
   atom    3                 :    6.255800601     (  0.1372672035E-04)\
   atom    4                 :    6.255800601     (  0.1372672035E-04)\
   atom    5                 :    6.255800601     (  0.1372672035E-04)\
   atom    6                 :    6.255800601     (  0.1372672035E-04)\
 total in muffin-tins        :    70.50595099    \
 total calculated charge     :    89.99779753    \
 total charge                :    90.00000000    \
 error                       :   0.2202465002E-02";

var bits = charges.split("species");
writeln(bits.size);

var morebits : domain(string);
  
for i in 0..bits.size-1 {
  morebits = bits[i].split("total in muffin-tins");
  writeln(morebits.type : string);
}
writeln(morebits.size);

for i in 0..morebits.size {
  writeln(morebits[i]);
}

I don't understand what is wrong with it.

Thanks for your help.
Cheers,
Roger

Hi Roger -

I'm seeing (with the version just after 1.33 on main) the error you mention on line 34:

var morebits : domain(string); // this is declaring an associative domain (kindof like a set)
// ...
for i in 0..morebits.size {
  writeln(morebits[i]); // error: domain slice requires a range in at least one dimension
}

The issue is that morebits is a domain. While domains support slicing (with, say, another domain, to compute an intersection), they don't support element access. Here i is an int.

(That said, since morebits is an associative domain, you wouldn't be able to slice it with a range anyway, and so the error message is misleading).

Here it looks like your intention is to iterate over the indices in the domain and to print them out. You could use this loop to do so:

for i in morebits.sorted() {
  writeln(i);
}

If you just use for in morebits it will work but you might see a different output ordering run-to-run, since the associative domain is supported by a hashtable. That is the reason I showed morebits.sorted() here.

1 Like

Hi Michael,

Michael Ferguson via Chapel Programming Language notifications@chapel.discoursemail.com writes:

  • mppf
    December 20

Hi Roger -

I'm seeing (with the version just after 1.33 on main) the error you mention on line 34:

var morebits : domain(string); // this is declaring an associative domain (kindof like a set)
// ...
for i in 0..morebits.size {
writeln(morebits[i]); // error: domain slice requires a range in at least one dimension
}

The issue is that morebits is a domain. While domains support slicing (with, say, another domain, to compute an intersection), they don't support element access. Here i is an int.

(That said, since morebits is an associative domain, you wouldn't be able to slice it with a range anyway, and so the error message is misleading).

Here it looks like your intention is to iterate over the indices in the domain and to print them out. You could use this loop to do so:

for i in morebits.sorted() {
writeln(i);
}

If you just use for in morebits it will work but you might see a different output ordering run-to-run, since the associative domain is supported by a hashtable. That is the reason I
showed morebits.sorted() here.

Thank you Michael for your code and explanation.

Season's greetings,
Roger

2 Likes