Before the lab
Read FICS Section 6
Read about Signatures
labs/L07
inside your ~/cs2613
git repositoryfoldr
Form a group of 2 or 3.
Work together to solve FICS Exercise 27
Contracts were introduced in The Design Recipe
Optionally write your contract in the form of a signature
Here is an implementation of foldr
, with the
name changed so as not to conflict with the builtin. It is often
easier to infer a type from a (simple) implementation.
(define (Foldr combine base lst)
(cond
[(empty? lst) base]
[else (combine
(first lst)
(Foldr combine base (rest lst)))]))
This part of the lab is based on FICS Exercise 29
Fill in the two instances of ...
in the following template with a
builtin function so that the tests pass. Try some other values for
mylist
, mylist1
, mylist2
to help you guess.
#lang htdp/isl+
(define mylist '(1 2 buckle my shoe))
(check-expect (foldr cons empty mylist) (... mylist))
(define mylist1 '(3 4 5))
(define mylist2 '(1 2))
(check-expect (foldr cons mylist1 mylist2) (... mylist2 mylist1))
foldr
fit your contract above? If not, how can
you fix your contract.On your own, complete FICS Exercise 28
You will have to rename the function to Filter
to avoid colliding with the builtin filter
.
You will need to use the language htdp/isl+
or "Intermediate Student with Lambda"
Your solution should pass the following test cases. odd?
is a
builtin function.
The previous part (Ex. 29) may give you some ideas about how to do this part.
(check-expect (Filter (lambda (x) #f) '(1 2 3)) '())
(check-expect (Filter odd? '(0 1 2 3 4 5 6 7 8 9))
(list 1 3 5 7 9))