blob: 09ff32470f1aa8a9806b613dcc3db7be886b2b6a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
; P19 Rotate a list N places to the left.
(def a (list "a" "b" "c" "d" "e" "f" "g" "h"))
(func rotate (lst cnt)
(branch
((eq? 0 cnt) lst)
((> cnt 0)
(rotate (append (rest lst) (first lst)) (- cnt 1)))
((< cnt 0)
(rotate (prepend (most lst) (last lst)) (+ cnt 1)))))
(print (->string a))
(print (->string (rotate a 3)))
(print (->string (rotate a (- 2))))
|