On this page:
1 Looking for it
2 Making ripples

Lab 6: More fun with files and lists

Important Note Whenever we say to "design a function", we mean that you need to follow the design recipe. Any other time that you write a function in this class, you also need to follow the design recipe.

1 Looking for it

Recall data definitions for lists from class.

Exercise 1 Write down the data definition for a ListOfStrings. Define three examples of ListsOfStrings. Write down the template for a function that processes a ListOfStrings.

Exercise 2 Design a function has-word? which consumes a ListOfStrings and a String, returning true if the given string is in the given list and false otherwise.

Exercise 3 Download the following five text files into the same folder as the file where you are completing this assignment:
Define a constant ListOfStrings called file-names containing the names of these files. You can use these names in your check-expect tests for later problems.

Exercise 4 Design a function file-has-word? which takes two Strings (a file name and a word to search for) and returns true if the corresponding file contains the given word.

You will need to use the 2htdp/batch-io package to examine the contents of files. You should use the built-in read-words function to create a ListOfStrings from a text file.

Exercise 5 Design a function search-files which takes a ListOfStrings (a list of file names) and a String (a word to search for) and produces a ListOfStrings that contains only those file names corresponding to files that contain the given String. In your check-expect tests, only use the names of the files you just downloaded.

Exercise 6 Use search-files to compute which of the files in file-names contain the word "it". Include this list with your submission.

2 Making ripples

For this exercise, you’ll be using big-bang to create a world which starts out as an empty scene, and creates growing circular ripples everywhere you click on the screen. The ripples should be a hollow circles that start with radius 1 and grow bigger as time passes.

Exercise 7 Come up with a data definition appropriate for representing the world in this program. Define three examples of your data definition.

Exercise 8 Write the template for processing this data definition.

Exercise 9 Design the to-draw, on-tick, and on-mouse functions for this big-bang program and write the big-bang expression.