CS212 Exams
Spring 1999 - Prelim
2

Mutable Functions


Write a function filter-tail! which when given a list X and predicate P filters out all elements of the tail of X for which P evaluates to #f by destructively updating the list. (The function may return any value and should ignore the case when X is empty.) For example:

==> (define x (list 1 2 3 4 5 6 7 8 9 10))
==> (filter-tail! even? x))
==> x
(1 2 4 6 8 10)

Solution

Return to CS 212 Prelim 2 - Spring 1999