Page 1: Walking Down a List
Unit 8, Lab 4, Page 1
In this lab, you will use your skills with recursion to build some advanced functions.
On this page, you will investigate a common code pattern.
It’s a big simplification to say that adding “s” always forms the plural. If you did the optional project on Plurals and you like, you can use your work from the plural block you made in Unit 2.
Here’s the plurals block from Lab 1. It takes a list of words as input, and reports a list of the plurals of those words. Although there is a way to build this block using map, bear with us: there is a good reason to investigate this recursive version.

The big idea here is that you can divide a list into its first item and all the rest of the items, form the plural of the first one, and make a recursive call for the rest. The in front of block may look strange at first, with its asymmetrical inputs (one item, one list), but it puts the plural of the first word and the plurals of the rest of the words back together.
This pattern of code can be used to build many useful recursive reporters that have a simple base case and a simple recursive call.
Do the following exercises using recursion, not higher-order functions.
Try modifying the code from
plurals.Make a
squaresblock that takes a list of numbers as input, and reports a list of the squares of the numbers.
Make an
exaggerateblock that takes a sentence as input, and reports a sentence in which every number in the input is doubled, “good” is replaced by “great,” “bad” is replaced by “terrible,” “like” is replaced by “love,” and “dislike” is replaced by “hate.”
To do this, first import the “Words, sentences” library. Then use a “wrapper” function that transforms the sentence into a list of words and back again:

What should the helper function do with the other words?
It’s the
exaggerate wordlistblock that will be recursive.You’ll also want a helper function
exaggerate wordthat works on a single word, looking for specific words and types to exaggerate.
“U8L4-Building-HOFs”
