Plurals, continued

In this lab, you will continue to 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.) You will also need your list of words that plural did not pluralize correctly.

  1. Abstraction: Make a plural block that "specializes" on just one category, words that end with the letter h.

    This specialist block should work correctly for words that fit its specialty plural (for words ending with h) with correct  result for the word crutch suffix s (for words ending in h) with result for moth, plural (for words ending in h) with result. It can be completely wrong about words that don't fit its specialty plural (for words ending with h) with wrong result for mouse (wrong input) because the plural block should never give words to h-plural unless those words end with h.

    Test plural with a variety of words to make sure it works the way you want.

  2. 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.

    I think we should use a some with "..." written with text. This looks like "·" is a block that we just don't know.

    abstract definition of plural: if h = last letter of word, report h-case plural; if y = last letter of word, report y-case plural; if some other case, use a block that specializes in that case; etc.; else report join word s

    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.

  3. When you trust your new specialist block, edit your original plural block to use your new specialist. Test your revised plural block to make sure it still works for all the words it used to work for, as well as the new ones.
  4. Take the next step. Create plural-y to handle words like this. plural_y-tray-with-result plural_y-sky-with-result
  5. As before, this specialist can make mistakes if it is asked to do a job that isn't its specialty plural_y-mouse-with-(wrong)result.

    plural will take care to give it only the cases it knows how to handle correctly.

 
  1. Extend plural to handle another special case, using a special-purpose block to keep plural from becoming cluttered with details. (Choose whatever special case you like. Some extensions will become easier when you learn more about lists in Unit 3, but even now you can handle some new cases.)
  2. An important idea lurks here: Right now, if plural is given a word with a space at the end, it leaves that space in the plural, like this: plural of bulldog with space at the end, and result with space before s. Figure out how to handle this special case and edit plural so that the result is plural of bulldog with space at the end, and correct result, no space before s? You already have a block that specializes in making plurals of words that don't have a space at the end. You can use it.
  3. Once plural works for a single space at the end of a word, try giving it plural of bulldog with four spaces at the end. Challenge: Explain why that works!