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

Supplemental 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

Primary: Students use different representations of functions to define Row-based functions.

Secondary: Students 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 their 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 questions 1-3 on Making Connections.

Investigate

The Design Recipe uses multiple representations of functions in a specific order to help us solve problems. Let’s look at an example to see how this works!

Complete the rest of Making Connections.

Review student answers, paying particular attention to the connections between "Contract and Purpose" and "Examples".

Take a closer look at the four examples in this file:

# 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. But these examples only tell us part of the story!

In those first examples, where are the number 3 and 1 coming from?

The first two examples are correct, but they don’t show all of their work. The last two examples show 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

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.

🔗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

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:

★ When a team has completed these three Design Recipes, they can use Composing Table Operations.

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

Who’s Doing What During Each Round of Design Recipe Telephone?

Round 1 - Writing Contract and Purpose Statements from the Word Problem

Student 1 - Problem A

Student 2 - Problem B

Student 3 - Problem C

everyone folds over the previous section, and passes their paper to the right

Round 2 - Writing Examples based solely on the Contract and Purpose Statement

Student 1 - Problem C

Student 2 - Problem A

Student 3 - Problem B

everyone folds over the previous section, and passes their paper to the right

Round 3 - Writing Function Definitions based solely on the Examples

Student 1 - Problem B

Student 2 - Problem C

Student 3 - Problem A

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?

    • Sample Responses:

    • 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?

🔗Additional Exercises

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.