On this page:
1 Warmup
2 Book exercises
3 Mutually Recursive Data Definitions
6.10.1

Assignment 10: Mutual recursion

This assignment is due on Wednesday, 11/01 at 11:59 PM. Submit it using the Handin server as assignment a10.

Use the Intermediate Student Language with lambda on this and further assignments in this course.

1 Warmup

Exercise 1 Recall Calder mobiles from Assignment 7. Design a function heavy-leaves that takes a [ListOf Mobile] and a Number as input and counts throughout the given list how many leaves are heavier than the given weight.

2 Book exercises

Exercises 323, 388, 389, 390

3 Mutually Recursive Data Definitions

Many documents, like textbooks, technical papers, and these lab notes, are often organized hierarchically: parts are composed of chapters, which are composed of sections, which are composed of subsections, and so on. Here are some data definitions that a program might use to process such documents:

(define-struct section (title text subsections))
 
;; A Section is (make-section String [ListOf String] [ListOf Section])
;; where the title field is the name of the section,
;; the text field is the words in the section,
;; and the subsections field is the contents of the section.

Exercise 2 Define at least two examples of Sections. Don’t worry about representing a real document yet; instead, you should be concerned with understanding how to build Sections and what they look like.

Exercise 3 Write the appropriate templates to process a section and a list of sections.

Exercise 4 Design a function search-section which given a section and a word, will return a list of names of each section which has text that contains the given word. Don’t return the name of a section just because it contains a subsection that contains the given word.