The lab is done in groups of 2 or 3.
Your goal is to explore abstraction by starting with two or three
examples and generalizing to a function that takes another function as
a parameter. Use examples on the resources
page for similar tasks that we did in class.
Make sure to switch DrRacket language to Intermediate student with
lambda (even if you are not using lambda
.
Since we haven't spent much time on writing general signatures, you are
not required to write them. However, correct signatures for
the general functions in tasks 1 and 2 would give you 2 points of extra
credit each (and a good attempt would give you partial credit).
Signatures for specific functions (for instance, functions that take a list
of numbers) are required.
#true
if all elements of the list are odd and #false
otherwise.
Make sure to test the function well.
#true
if the string has length of 5 characters or less and #false
otherwise. #true
if all elements of the list are of length 5 or less and
#false
otherwise. You must use your helper function.
all?
that takes
a list and a predicate and returns #true
if all the elements on the list satisfy the predicate and
#false
otherwise. all?
to
perform the tasks in the first two questions. In the first case the
predicate that you pass to it is odd?
. In the second case
it's the helper function in question 2.
#true
if all numbers on
a list of numbers are negative. Hint: use the predicate
negative?
.
Note: do not use andmap
for this problem. Write your own
recursive functions.
#false
is returned.#false
if there
is no such element), but works on a
different data type (such as a list of strings, or images, or
structures).
In this task you will be using map
and filter
general functions given
here to perform different tasks. You can use helper functions when
the functions that you need you need to pass to map
or
filter
aren't defined in Racket. You may use lambda
if you would like (see section 17.1 in the book), but this is by
no means required.
Below are a couple of examples for using the predefined functions (without a lambda):
;; using map to produce square roots of a list of numbers:
(map sqrt (list 0 1 2 4 5))
;; legal? : posn -> boolean
;; The function takes a position structure and returns
;; #true if it's within 400-by-400 scene, and #false
;; otherwise
(define (legal? p)
(and (>= (posn-x p) 0) (<= (posn-x p) 400)
(>= (posn-y p) 0) (<= (posn-y p) 400)))
;; using filter and a helper function legal? to select only legal
;; positions in a list of position structures
(filter legal? (list (make-posn 200 0) (make-posn 401 50) (make-posn -10 200) (make-posn 100 300)))
Your task is to use map
and filter
to do the following:
Name your file with the combination of your last names, no spaces, followed by the word "Lab"
and the lab number.
For instance,
if your last names are Smith and Lee, the file name should be SmithLeeLab7.rkt
If there are others in the class with the same name as yours, you your initial in addition
to your last name: MSmithJLeeLab7.rkt
At least one person in the group must submit it via canvas as a file upload (make sure it's that .rkt
file).
Make a comment indicating who you worked with. The other person (or people) in the group may submit the same file and also
indicate who was in the group or just make a comment listing all your group members (note: if you don't submit a note listing
your group members,
your work may not be counted, even if your group partners list you as the group member).