; dutch national flag
(define examine vector-ref)
(define (swap! xs p1 p2)
(let ((t (vector-ref xs p1)))
(vector-set! xs p1 (vector-ref xs p2))
(vector-set! xs p2 t))
xs)
(define (dutch-national-flag xs)
(let loop ((r 0) (w 0) (b (- (vector-length xs) 1)))
(if (< b w) xs
(case (examine xs w)
((#\R) (set! xs (swap! xs r w))
(loop (+ r 1) (+ w 1) b))
((#\W) (loop r (+ w 1) b))
((#\B) (set! xs (swap! xs b w))
(loop r w (- b 1)))))))
(display (dutch-national-flag #(#\B #\W #\B #\R #\W #\R #\B)))