Exploring List Processing

Brian's Notes from late July 2016:
  1. Load this Snap! project.
  2. List of Data about Brazil For each of the following reporters, discuss what you think it does. Then, experiment using the Brazil data list (shown right) and see what happens.
    1. length of {}
    2. all but first of {}
    3. () in front of {}
  3. The item (1) of {} reporter has a dropdown with three options: 1, random, and last, but that input also accepts an expression or a number. Experiment. Discuss how you might use this block in a program. Talk with Another Pair
    • How would you use item to report just the language spoken in Brazil?
    • How would you use it to report the last name of the current president (Roussef)?
    • How would you use it to report the population in 2015?
    • How would you use it to report only the symbol used for Brazilian currency (R$)?
  4. What is the difference between item-2-of-list(Russia-Haiti-Japan-Brazil-Rwanda-VietNam) and list(Haiti)?
  5. Look back at the Brazil list and use contains to compare "contains Brasilia" with "contains Roussef." Explain why the latter ("contains Roussef") fails.
  6. What do each of the following return? Guess first; then build in Snap!  Then, discuss why the expressions return what they do.
    1. length-of-all-but-first-of-list(Russia-Haiti-Japan-Brazil-Rwanda-VietNam)
    2. Talk with Your Partner
    3. length-of-list(blank-Haiti-blank-blank-Rwanda-blank)
    4. length (empty list)
    5. keep-items-such-that-a-equals-letter-3-of()-from-list(Russia-Haiti-Japan-Brazil-Rwanda-VietNam)
    6. keep-items-such-that-a-equals-letter-6-of()-from-list(Russia-Haiti-Japan-Brazil-Rwanda-VietNam)
    7. keep-items-such-that-a-equals-letter-1-of()-from-list(Russia-Haiti-Japan-Brazil-Rwanda-VietNam)
    8. keep-items-such-that-6-equals-length-of()-from-list(Russia-Haiti-Japan-Brazil-Rwanda-VietNam)

Keep applies a test (its first input) to each item of a list (its second input), and reports a list containing only the matching items. If no items satisfy the test, keep reports an empty list.

Explaining Keep items such that

  1. Figure out two different tests to use withkeep items such that () from () on the listlist(Russia-Haiti-Japan-Brazil-Rwanda-VietNam) so that keep reports {Haiti, Japan}
  2. Find a way to use keep with the same list, so that your code reports only the countries from the list with names longer than 7 characters.
  3. Set Up Your Headphones or Speakers
  4. Build and compare these play scripts. Run each script a few times.
    1. play note (item (any) of (list (60) (64) (67) (72) (60))) for (1) beats
    2. for each (note) of (list (60) (64) (67) (72) (60)) (play note (note) for (1) beats)
    3. for each (note) of (map (_ + 5) over (list (60) (64) (67) (72) (60))) (play note (note) for (1) beats)
    4. for each (note) of (keep items such that (_ < 65) from (list (60) (64) (67) (72) (60))) (play note (note) for (1) beats)
    5. join (C major: ) (combine with (join () (, ) ()) items of (list (60) (64) (67)))