Chapel has a reverse()
operator for arrays, but I can't seem to make it work on domains
var v = {1..8};
for w in v {
writeln(w);
}
// poops
for w in reverse(v) {
writeln(w);
}
How do I go backwards?
Chapel has a reverse()
operator for arrays, but I can't seem to make it work on domains
var v = {1..8};
for w in v {
writeln(w);
}
// poops
for w in reverse(v) {
writeln(w);
}
How do I go backwards?
You can accomplish this by iterating over v
with a stride of -1
:
for w in v by -1 {
writeln(w);
}
These range operations work on both ranges and domains. More on that in the Ranges Primer.