Teacher's Choice

Nesting Function Calls (Teacher's Choice)

Here are 3 powerful higher-order functions (functions that take other functions as input):

The three can be used together to build more advanced functions.

Character Encoding

Every character you type is encoded by the computer as a number. Unicode assigns a number to every letter that can be typed in any language, as well as to special characters, such as !, @, #, ö, λ, ♣, and the space bar.

ASCII is a small subset of Unicode that includes letters, numbers, and a few symbols. The list of Unicode characters is much longer.
I included this because 1) I think it's nice to get a visual sense of what's going on here. It's not rocket science, it's just a little cipher. And 2) it prepares them for what they will see on the exam.


AC: I can imagine kids getting confused because the chart doesn't contain integers > 70.
Mary: The idea of the chart is fine (although it kind of defeats the purpose of FYTD #1) but I think the headings on this chart are confusing. It's not the characters that are ASCII; it's the numeric code. Really the columns should be swapped and the headings should be "Character" and "Unicode value." This also eliminates having to raise the unnecessary confusion of ASCII vs. Unicode. --bh
ASCII chart for capital letters
  1. Use the green block unicode of (a) to figure out the unicode for "A", "Z", "a", and "z".
  2. Use the green block unicode(65)as letter to figure out the letter for the unicode numbers 72, 105, 33.
  3. Use those blocks, along with the higher order functions from the previous lab, to decode this message:
    list of unicode numbers
  4. You may have built a unicode encode block in Unit 2 Lab 2: Script Variable Projects. If so, compare the technique you used then with the technique you used now with lists. How do they differ?
    Write a block encode (message) that takes an input message (a sentence), tears it into letter-sized chunks, gets the unicode, adds 1 to each letter, and reports the encoded message.
  5. Build a decode (message) block to reverse encode (message).
  Tough Stuff
You could use mod to make the letters of the alphabet loop around to the beginning. You will need to take into account that A is 65.
  1. Build an encode (message) by (offset) block that takes an input message and an offset value, gets the unicode of the message, adds the offset to each letter, and outputs the encoded message.
  2. Build a decode (message) by (offset) block that takes an input message and an offset value and reverse encode (message) by (offset).

Acronym Generator

An acronym is a "word" made up of the first letters of every capitalized word in a phrase. For example, the acronym for United States of America is USA, and SUNY is an acronym for State University of New York.

In this project, you will create a reporter block that takes a phrase as input and reports an acronym made only from the capitalized words. It should work like this:
Beauty and Joy of Computing: BJC New York City: NYC

  1. Create a reporter that takes a phrase as input and reports an acronym made of the first letters of the capitalized words. The steps below suggest one way:
      Import Tools
    1. The input phrase is a string of characters. Break it up into a list of words.
    2. There are many ways to turn a string like "Beauty and Joy of Computing" into a list of words. One way is to use this green block: sentence to list (pronounced "sentence to list"). It lets you break a string at every space and convert the string to a list of words. It's in the Tools library.
      The unicode of block will be helpful here.
    3. You have choices about the next step. You could use map to generate a new list containing only the first letters of the words in your input list, and then keep only those that are capital letters. OR, you could keep only the words that begin with capitals and then use map to create a list containing only the first letters of those words.
    4. Save Your WorkLast, you need to convert that list back into a string.
  1. Click the picture to load this database project:
    database of name, job, salary
    This is the list of employees of a small company. (Taken from Structure and Interpretation of Computer Programs by Abelson and Sussman. Creative Commons licensed.) Each of the smaller lists contains a person's name, job title, and yearly salary.

    "This company spends more money on the big bosses than on the people who do the work," says Alyssa one day. Is she right? Write an expression to compute the total salaries of everyone paid less than $100,000 per year. Then find the total for everyone paid more than $100,000 per year.

  2. Ben suggests that the results will be more convincing in the form of a list containing that total and all the names of the people in that category (paid less than $100,000, for example). So, if there are five people in that category, your list will have six items: first the total of the salaries, and then the names of the people. Try this both for less than $100,000 and for more than $100,000.
  3. Find the average salary of people paid less than $100,000 per year.