You may work in groups of 2 (preferred) or individually.
At the end of the lab please send me and your group partner(s) all your Scheme files as e-mail attachments. My e-mail is elenam at morris.umn.edu. The subject of your e-mail must be "1301 Lab 8" followed by "Final" or "Not final", depending on whether this is a final submission or you are still working on it. If you need to finish it, make sure to set up a time with your group partner(s) to finish the lab.
Due Tuesday, December 1st, at 11:59pm. If you submit the final version during the lab, you are done.
Question 1
Write a function that builds filter functions, similarly to a building
function for map
or foldr
here.
Your function must take one parameter (the filtering criterion which is
a function) and
returns a function that filters a list according to that
criterion. For instance, using the filtering function builder allows us
to create a function to filter out all numbers divisible by 3 by
passing an appropriate criterion function to a
filter-builder
.
You may use local
or lambda
to define the function.
Use your function to define the following functions. Use lambda
to define the criterion function that is passed to filter-builder.
filter-div3
that takes a list of integers and creates a
list of all its elements divisible by 3. For instance:
(check-expect (filter-div3 (list 2 21 22 33 -1 -3)) (list 21 33 -3))
filter-longer-than-3
that takes a list of lists and leaves only
lists of length 3 and shorter:
(check-expect (filter-longer-than-3 (list (list 1 2 3 4) (list 1 2) (list 1 2 3) (list 1 2 3 4 5)))
(list (list 1 2) (list 1 2 3)))
filter-a-b
that removes all symbols from a list of symbols that
are not 'a or 'b:
(check-expect (filter-a-b (list 'a 'c 'b 'd 'a)) (list 'a 'b 'a))
Exercises 23.2.2, 23.2.3, 23.2.4, 23.2.5
The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.