I'm converting Advent of Code solutions from VBA (twinBasic) to Nim
I have a bit of a headscratcher when it comes to implementing the Step
functionality in 'for x to y step z' because in VBA step can be a positive or a
negative value wheres nim uses countup or countdown iterators with the step
value always being a positive number
Dim myXStep As Long = If(s.X1 <= s.X2, 1, -1)
For myXCoord = s.X1 To s.X2 Step myXStep
Run
I tried being clever with this code in nim
var myXStep:iterator [T](a, b:T): T = if s.X1 <= s.X2: [T]countup(a,b:T)
else: [T]countdown(a,b:T)
Run
so that I could then write
for myX in myXstep(s.X1,s.X2)
Run
but it doesn't work, even when I convert the 1 line version to a multiline
version
I have elsewhere successfully used something similar to the above to provide
procs as a parameter but I'm obviously not quite there yet with the above
attempts.
Advice would be welcome.