UNB/ CS/ David Bremner/ teaching/ cs2613/ labs/ Lab 7

Before the lab


Questions

Time
5 Minutes
Activity
Group discussion / Announcments

Setup

Introducing foldr

Time
25 minutes
Activity
Small groups
Summary
foldr, functional_abstraction, contracts
(define (Foldr combine base lst)
  (cond
    [(empty? lst) base]
    [else (combine
            (first lst)
            (Foldr combine base (rest lst)))]))

Guess the function

Time
25 minutes
Activity
Individual work
Summary
foldr, functional_abstraction, lists

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))

Filter in terms of foldr

Time
40 minutes
Activity
Individual work
Summary
foldr, functional_abstraction, lists

On your own, complete FICS Exercise 28

(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))

Before next lab