instagram

Students use the Design Recipe to define functions that consume rows, developing a structured approach to answering questions by transforming tables.

Lesson Goals

Students will be able to…​

  • write functions that consume a Row and perform a lookup to produce a column

  • write functions that consume a Row and compute to produce an Image

  • write functions that consume a Row and compute to produce a Boolean

Student-facing Lesson Goals

  • Let’s define functions that look up values from a Row.

  • Let’s define functions that produce Images from a Row.

  • Let’s define functions that compute a Boolean from a Row.

Materials

Preparation

To do the Design Recipe Telephone activity, you will need to decide on groups of 3 and print copies of the word problems that you will be using. (A class of 30 will only need 10 copies of each Design Recipe problem.)

🔗Reviewing Function Definition 15 minutes

Overview

Students use different representations of functions to define functions that consume Rows, discover functions that consume other functions, and compose a scatter plot function with a function they’ve defined.

Launch

By now you’ve had a chance to explore functions on your own, thinking of them in terms of several different representations:

  • A mapping between Domain and Range

  • A list of discrete input values and output values

  • A symbolic definition

Now it’s time to use those representations to help us work with Tables!

  • Open the Row Functions Starter File, save a copy, and click "Run".

  • Scroll until you see the definition for cat-row. What will you get back if you evaluate cat-row in the Interactions Area?

  • What species is the animal?

  • What is its name?

  • How old is it?

  • Complete the first section of Making Connections (questions 1-4).

Investigate

You’ve already had a chance to work with the Design Recipe.

Each step in the Design Recipe helps us write the next one.

  • If we can’t write our Contract and Purpose, it means we haven’t thought through the problem enough. Better to find this out before we write the rest of our function!

  • If we’re having trouble writing our Examples, we can check our Contract and Purpose for hints.

  • If we’re having trouble writing the Definition, we can check our Examples to see the pattern.

These steps also help us check our work. If any two representations don’t match, it means there’s likely a bug somewhere.

Let’s look at an example to see how this works with table-functions!

Complete the weeks-dot section of Making Connections.

Review student answers from the weeks-dot section of Making Connections, paying particular attention to the connections between "Contract and Purpose" and "Examples".

# weeks-dot :: Row -> Image
# consumes an animal, and draws a solid purple circle whose
# radius is 5x the number of weeks it took to be adopted
examples:
  weeks-dot(cat-row)   is circle(5      *      3        , "solid", "green")
  weeks-dot(young-row) is circle(5      *      1        , "solid", "green")

  weeks-dot(cat-row)   is circle(5 * cat-row["weeks"]   , "solid", "green")
  weeks-dot(young-row) is circle(5 * young-row["weeks"] , "solid", "green")
end

These examples show us exactly what should be produced for cat-row and young-row - the two Rows representing "Sasha" and "Wade", based on their weeks to adoption.

  • Take a closer look at the examples.

  • Think about how the first pair of examples relates to the second.

Both pairs of examples are correct!

In the first pair, we see the values 3 and 1 , but no explanation of where they are coming from. The last pair shows how those values are looked up from the example rows.

If you’re stuck on the examples step, here’s a useful trick to get you started. Complete the following sentence:
"For this Row, I…​"
Whatever you answer is the precise description of what to do for your example!

You can use both kinds of examples in your code!

  • Sometimes we want to use real, concrete numbers to make sure our work is correct.

  • And sometimes we need to show all of our work, to make sure we are defining the function correctly!

Programmers often use a mix of the two.

Synthesize

Why might it be beneficial to include both kinds of examples?

🔗Design Recipe Telephone 40 minutes

Overview

Students work in teams to collaboratively define multiple Table Functions. When these functions are composed in different ways, they can be used to do much more sophisticated analysis!

Launch

Why would it be challenging to make the following displays?

  • a box plot showing the distribution of kilograms across old cats at the shelter

  • a scatter plot showing the relationship between kilograms of young dogs at the shelter, and how many days it took to be adopted

There would be a lot of steps involved!

Most computer programs are written by huge teams! It is critical that each team member records their thinking with enough detail for other team members to be able to pick up where they left off.

We’re going to practice collaborative programming and try writing some other Table Functions using the Design Recipe, through an activity called Design Recipe Telephone.

Investigate

  1. Divide the class into groups of three.

  2. Choose which set of word problems you are going to start with and give each student within each group a different word problem from the set.

Word Problem Set 1: Word Problem Set 2:
  • In this activity, each person in your group will start with a different word problem. You will each be doing one step of each Design Recipe problem. After you complete your step, you will fold your paper to hide the part that you were looking at so that only your work and the rest of the recipe are visible. Then you will pass your work to the person to your right.

  • The person who has received your paper will review your work and complete the next step based solely on what you wrote down for them. If they don’t have the information they need, they will give the paper back to you for revision.

  • Meanwhile, you will receive a different problem from the person to your left. If at any point your realize that the person before you didn’t provide enough information, you may hand the paper back to them for revision.

Round 1:

You should have a page with a Word Problem.

  • Write the Contract and Purpose Statement.

  • Fold your paper to hide the Word Problem.

  • Pass your paper to the person to your right.

Round 2:

You should have just received a new page, that has been folded to hide the Word Problem.

  • Write Examples from the Contract and Purpose Statement.

  • Circle the Variables.

  • Then fold your paper to hide the Contract and Purpose Statement.

  • Pass your paper to the person to your right.

Round 3:

You should have just received a new page that has been folded so that the Examples are at the top.

  • Write a Definition from the Examples you just received.

  • When you’re done, pass your paper to your right to return it to the person it started with.

Round 4:

You should now be holding the page you started with.

  • Unfold the page and type the full Design Recipe into the Definitions Area of the Animals Starter File.

  • If your function is a Boolean-producing function, make sure that at least one of the examples should produce true and at least one should produce false. If not, add an additional example.

  • Click "Run" and confirm that all tests pass.

  • If not, collaborate with your team to identify which steps of the Design Recipe need to be reworked.

This activity can be repeated several times, or done as a timed competition between teams. The goal is to emphasize that each step - if done correctly - makes the following step incredibly simple.

Synthesize

The Design Recipe is a way of slowing down and thinking through each step of a problem.

  • If we already know how to get the answer, why would it ever be important to know how to do each step the slow way?

    • Someday we won’t be able to get the answer, and knowing the steps will help

    • So we can help someone else who is stuck

    • So we can work with someone else and share our thinking

    • So we can check our work

  • Why is it helpful to use each of these steps in the Design Recipe?

  • What step do you find the most challenging right now? The easiest?

  • What are some functions you might want to define for your own analysis?

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.