(define (filter p? xs)
(cond ((null? xs) '())
((p? (car xs))
(cons (car xs)
(filter p? (cdr xs))))
(else (filter p? (cdr xs)))))
(define (sort f xs)
(if (null? xs) '()
(let* ((pivot (car xs))
(left (filter (lambda (x) (f x pivot)) (cdr xs)))
(right (filter (lambda (x) (not (f x pivot))) (cdr xs))))
(append (sort f left) (list pivot) (sort f right)))))