Hi
I have been wondering why `..` operator works only for countup. Why there is no counterpart for couontdown?
For instance something like:
when sizeof(int) <= 2:
type IntLikeForCount = int|int8|int16|char|bool|uint8|enum
else:
type IntLikeForCount = int|int8|int16|int32|char|bool|uint8|uint16|enum
iterator `..`[S, T](a: S, b: T): T {.inline.} =
dbg("Using .. for ", a, ", ", b)
if a > b:
when T is IntLikeForCount:
var res = int(a)
while res >= int(b):
yield T(res)
dec(res, 1)
else:
var res = a
while res >= b:
yield res
dec(res, 1)
else:
when T is IntLikeForCount:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res)
else:
var res: T = T(a)
while res <= b:
yield res
inc(res)
Perhaps it is naive approach but I assume that it could be written to resemble currently existing `..` implementation.
From system.nim
iterator `..`[S, T](a: S; b: T): T {..}
An alias for countup. Source Edit
Anyway, could not it work with a > b? Probably there is some reasoning behind this and I am trying to understand.