treversable.nim 484 B

1234567891011121314151617181920212223242526272829303132
  1. # issue 7705, 7703, 7702
  2. discard """
  3. output: '''
  4. z
  5. e
  6. '''
  7. """
  8. type
  9. Reversable*[T] = concept a
  10. a[int] is T
  11. a.high is int
  12. a.len is int
  13. a.low is int
  14. proc get[T](s: Reversable[T], n: int): T =
  15. s[n]
  16. proc hi[T](s: Reversable[T]): int =
  17. s.high
  18. proc lo[T](s: Reversable[T]): int =
  19. s.low
  20. iterator reverse*[T](s: Reversable[T]): T =
  21. assert hi(s) - lo(s) == len(s) - 1
  22. for z in hi(s).countdown(lo(s)):
  23. yield s.get(z)
  24. for s in @["e", "z"].reverse:
  25. echo s