Given:
;;NumberList → NumberList
;; extract all items froml
that are larger thanpivot
(define (larger pivot l) (cond [(empty? l) empty] [else (cond [(> (first l) pivot) (cons (first l) (larger pivot (rest l)))] [else (larger pivot (rest l))])])) ;; test: (equal? (larger 3 (list 3 8 1 2 9 7)) (list 8 9 7))
Better:
;;NumberList → NumberList
;; extract all items froml
that are larger thanpivot
(define (larger pivot l) (local ((define (compare-item-to-pivot item) (> item pivot))) (filter compare-item-to-pivot l)))
Best:
;;NumberList → NumberList
;; extract all items froml
that are larger thanpivot
(define (larger pivot l) (filter (lambda (item) (> item pivot)) l))