Using Lists to Write Vowel?

snap lets you manipulate a variety of data types. You have already used blocks like letter, join, and join words to manipulate strings of characters such as "New York" or "Another hour has passed". You have also manipulated numbers.

This page introduces a new data type, lists. In Unit 3, you will study lists in depth.

  1. Instead of using many if statements in vowel?, you can make a list of vowels and then test to see if a particular letter is in that list. snap makes that a snap!
    1. Construct list (a e i o u), click on it, and see what it does. You will find the list block in the variables palette. Click on the list-block-right-arrow to make a space for each letter you need to add.
    2. The just the list a e i o u that you see when you click on list (a e i o u) is an artist's way of picturing a list inside the computer. The image numbers each item of the list and tells you how long the list is.
    3. Experiment with these blocks to see what they do.
      To save work, just duplicate list (a e i o u) a few times to use in each experiment.

      list (a e i o u) list a e i o u contains m list a e i o u contains e list of vowels contains randomly picked letter of pencil item pick random element from list of I you he she it we they

    4. Redefine vowel? using list and contains.
  2. Analyzing, and programming elegance: Here are two ways you might use list-(a-e-i-o-u)-contains (some letter) to redefine vowel?. With your pair programmer, figure out how each works. Decide which you find clearer.
    is letter a vowel (v4)
    is letter a vowel (v3)
  3. In the current version of Snap!, you must import tools to get map.
    import-tools-menu
    Make a list of at least 10 animal names (e.g., elephant, lion, antelope, eagle, bear, ...) and test the join "a" or "an" with block on the words in that list. Here are two ways to perform that test.
    map(join-a-or-an-with())over(list-elephant-lion-eel-mouse-anteater)
    join-a-or-an-with(item(random)of(list-elephant-lion-eel-mouse-anteater)