;;; Procedure: ;;; filter ;;; Parameters: ;;; lst, a list ;;; ok?, a unary predicate ;;; Purpose: ;;; Extract all elements of the list that meet the predicate. ;;; Produces: ;;; ok, a list of values that meet the predicates ;;; Preconditions: ;;; The predicate can be applied to every element in the list. ;;; Postconditions: ;;; ok contains only elements from lst ;;; ok? holds for every element of ok ;;; Does not modify lst (define filter (lambda (lst ok?) (cond ((null? lst) null) ((ok? (car lst)) (cons (car lst) (filter (cdr lst) ok?))) (else (filter (cdr lst) ok?)))))