```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ``` ```; reversing parts of a list (define (take n xs) (let loop ((n n) (xs xs) (ys '())) (if (or (zero? n) (null? xs)) (reverse ys) (loop (- n 1) (cdr xs) (cons (car xs) ys))))) (define (drop n xs) (let loop ((n n) (xs xs)) (if (or (zero? n) (null? xs)) xs (loop (- n 1) (cdr xs))))) (define (rev-2 xs) (let loop ((xs xs) (zs (list))) (cond ((null? xs) (reverse zs)) ((null? (cdr xs)) (reverse (cons (car xs) zs))) (else (loop (cddr xs) (cons (car xs) (cons (cadr xs) zs))))))) (define (rev-k k xs) (let loop ((xs xs) (zs (list))) (if (null? xs) (reverse zs) (loop (drop k xs) (append (take k xs) zs))))) (define (rev-half xs) (let loop ((t xs) (h xs) (zs (list))) (cond ((null? h) (append zs (reverse t))) ((null? (cdr h)) (append zs (reverse t))) (else (loop (cdr t) (cddr h) (cons (car t) zs)))))) (display (rev-2 '(1 2 3 4 5 6))) (newline) (display (rev-2 '(1 2 3 4 5))) (newline) (display (rev-k 3 '(1 2 3 4 5 6))) (newline) (display (rev-k 4 '(1 2 3 4 5 6))) (newline) (display (rev-half '(1 2 3 4 5 6))) (newline) (display (rev-half '(1 2 3 4 5))) (newline) ```
 ```1 2 3 4 5 6 ``` ```(2 1 4 3 6 5) (2 1 4 3 5) (3 2 1 6 5 4) (4 3 2 1 6 5) (3 2 1 6 5 4) (2 1 5 4 3) ```