Nice, though I'm used to shift meaning "remove the first value of the 
(resizable) array and return the value", I think your proc feels more like it's 
"scrolling" the array?

Anyway, naming aside, what do you think of this version? 
    
    
    proc scroll[T](a: var openarray[T]; d: int) =
      if d == 0: discard # do nothing
      elif abs(d) >= a.len: # reset all
        for el in a.mitems: el.reset
      elif d > 0: # right shift
        for i in countdown(a.len-1,d):
          a[i]=a[i-d]
        for j in 0..<d: a[j].reset
      elif d < 0: # left shift
        for i in -d..<a.len:
          a[i+d]=a[i]
        for j in countdown(-d,1): a[^j].reset
    

Reply via email to