Now you will improve your plural
block so that it works correctly with more words. If you do not already have it, please reload it. (The suggested file name was U2Lab1-Plural
.)
list
of the words you want it to work for.plural
block should never give words to plural-h
unless those words end with h. map
to test it on the entire list
you made earlier.Abstraction: English is complicated and has a lot of special cases. To pluralize some nouns, you add s; to some you add es; nouns like calf and fly become calves and flies, changing their final letters before adding es. And there are other special cases to handle. For a programming task this complex, it is (generally) best to break it into parts, handle each part separately with its own procedure (its own block), and then have the "top-level" block—in this case, plural
, itself—show only the outline. That is, instead of coding every little detail directly in plural
, it is cleaner and clearer to build a block that looks something like this, with each special case handled by block that specializes in that case only.
Showing the structure of the method—just the overall strategy—in the "top-level" block and relegating the details to separate blocks is one part of an important computer science idea called abstraction. This aspect of abstraction is extremely helpful in keeping your code clear and helping you debug it.
plural
block to use your new specialist. Test your revised plural
block (you can use map
) to make sure it still works for all the words it used to work for, as well as the new ones.plural-y
to handle words like this.
As before, this specialist can make mistakes if it is asked to do a job that isn't its specialty.
Make sure that plural
gives it only the cases it knows how to handle correctly.
plural
to handle another special case. Use a special-purpose block for your special case to keep plural
from becoming cluttered.plural
is given a word with a space at the end, it leaves that space in the plural, like this: plural
so that the result is plural
works for a single space at the end of a word, try giving it