clean-up
;; [Listof Posn] Number Number Number Number
;; ->
;; [Listof Posn]
;; remove specks that are inside of
;; the specified boundaries
(define (clean-up lop lft rgt top bot)
(cond
[(empty? lop) empty]
[else (local ((define fst (first lop))
(define rst
(clean-up
(rest lop) lft rgt top bot)))
(cond [(and (<= lft (posn-x fst) rgt)
(<= top (posn-y fst) bot))
rst]
[else (cons fst rst)]))]))
;; TESTS
(equal? (clean-up (list (make-posn 10 10)
(make-posn 100 50)
(make-posn 20 10))
10 20 10 20)
(list (make-posn 100 50)))
Solution:
;; [PTS 2: 1 for filter,
;; 1 for correctness (function, not)]
(define (clean-up lop lft rgt top bot)
(local ((define (outside? fst)
(not (and (<= lft (posn-x fst) rgt)
(<= top (posn-y fst) rgt)))))
(filter outside? lop)))