### 6.3.15 Rotating a list

The rotate command rotates a list; namely it moves elements from one side and puts them on the other.

- rotate takes one mandatory argument and one optional argument:
  - L, a list.
  - Optionally, n, an integer (by default n=−1).
- rotate(L) returns the list formed by rotating L n places to the left if n>0 or −n places to the right if n<0. Elements leaving the list from one side come back on the other side. By default n=−1 and the last element becomes the first.

#### Examples

rotate([0,1,2,3,4])

| ⎡ ⎣ | 4,0,1,2,3 | ⎤ ⎦

rotate([0,1,2,3,4],2)

| ⎡ ⎣ | 2,3,4,0,1 | ⎤ ⎦

rotate([0,1,2,3,4],-2)

| ⎡ ⎣ | 3,4,0,1,2 | ⎤ ⎦