t17460.nim 448 B

12345678910111213141516171819
  1. discard """
  2. cmd: "nim check $options $file"
  3. errormsg: "wrong number of variables"
  4. """
  5. iterator xclusters*[T](a: openArray[T]; s: static[int]): array[s, T] {.inline.} =
  6. var result: array[s, T] # iterators have no default result variable
  7. var i = 0
  8. while i < len(a):
  9. for j, x in mpairs(result):
  10. x = a[(i + j) mod len(a)]
  11. yield result
  12. inc(i)
  13. proc m =
  14. for (i, j, k) in xclusters([1, 2, 3, 4, 5], 3):
  15. echo i, j, k
  16. m()