We want a block that will take a list of words as input, and report a list of the plurals of those words.

You already know how to do this with a higher order function, and that's how you will do it in real life, but just for this lesson, pretend you don't know about HOFs and think about how to do it recursively.


Actually, if you're on the ball, you won't have to think very hard about it, because we showed you this block as an example in the first lesson about recursive reporters:

plurals bloc

(By the way, we know it's a vast oversimplification to say that adding an "s" forms the plural, but this is Computer Science class, not English class.)

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 probably looks strange when you first see it, with its asymmetrical inputs (one item, one list), but it's exactly the combiner we need to put the plural of the first word and the plurals of the rest of the words back together.


Do the following exercises using recursion, not HOFs.

☞ Make a squares block that takes a list of numbers as input, and reports a list of the squares of the numbers.

squares example

☞ Make an exaggerate block 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." Hint: You'll almost certainly find the all but first word of () and first word of () blocks useful. You can find these in the "Words, sentences" library (click the "file" icon, select "Libraries..."). Another hint: You'll probably want a helper function that exaggerates a single word. One more hint: It might help to look back at your exaggerate block from the lists lab.

exaggerate example