On Tuesday, 24 May 2016 at 12:22:01 UTC, H. S. Teoh wrote:
And why would you assume that it would rotate right? The default assumption, unless stated clearly and widely followed everywhere, is unclear and leads to misunderstandings.

hmmm rotate left would be a lot easier (and cleaner) to implement than rotate right..? And could include tail optimizations? If i consider a purely functional language where you have access to the left-side of the argument list but not the right side...

//Should probably heavily incorporate move as well...
//best if only bitwise-copies are necessary to swap/rotate values
void rotate(T...)(T[] arr) {
  T temp = arr[0];

  void inner(T[] vars) {
    if (arr.length > 1) {
      vars[0] = vars[1];
      inner(vars[1 .. $]);
    } else {
      vars[0] = temp;
    }
  }
  inner(arr);
}

Reply via email to