1

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?

Brian Dolan
  • 3,086
  • 2
  • 24
  • 35

1 Answers1

1

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.

ben-albrecht
  • 1,785
  • 10
  • 23