S-99-19 Rotate a list N places to the left.
Examples:
(rotate '(a b c d e f g h) 3) ; => (d e f g h a b c) (rotate '(a b c d e f g h) -2) ; => (g h a b c d e f)
Hint: Use the predefined functions length and append, as well as the result of S-99-17.
Solution:
(define (rotate xs n)
(if (< n 0)
(reverse (rotate (reverse xs) (- n)))
(let ((parts (split xs n)))
(append (cadr parts) (car parts)))))