From a list, you want only the elements that match certain criteria.
This notion of extracting a subset of a larger list is common. It's how you find all engineers in a list of employees, all users in the "staff" group, or all the filenames you're interested in.
The fist solution is with a plain loop. We traverse the list asking for each element in it.
;; filter*: (Value -> Boolean) -> List
;; To filter al the elements in the list l that match with the predicate pred
(define (filter*predicatel)
(letloop ((ll) (acc'()))
(cond
[(null?l) acc]
[(pred (carl)) (loop (cdrl) (appendacc (list (carl))))]
[else (loop (cdrl) acc)])))
You also can use the filter function that ships either in the SRFI 1 or in Mzlib. The signature of this filter is the very same that the one for filter*.
;; either
(require (lib"list.ss""srfi""1.ss" ));; for filter in the SRFI 1
;; or
(require (lib"list.ss""mzlib")) ;; for the one in Mzlib
;; and You are ready to go