Students will deepen their understanding of function definitions and the Design Recipe
Pens/pencils for students, fresh whiteboard markers for teachers
Class poster (List of rules, language table, course calendar)
Language Table (see below)
Student Workbook folders with names on covers, and something to write with
Write Agenda on board
Display class posters, Language Table, Design Recipe
In the previous unit, you reviewed almost everything from Bootstrap:1 including Datatypes, Contracts, and the Design Recipe. In this unit you will go above and beyond all that, and learn an entirely new construct that will be the basis for everything you’ll do in Bootstrap:2.
Ask a few introductory review questions to test students’ understanding:
What are the three parts of a Contract?
What is the Pyret code to draw a solid, green triangle of size 22?
Why is it important to write at least 2 examples before defining a function?
- To make sure the material from the previous unit is fresh in your mind, tackle the following activity:
Turn to Page 8 in your workbook. Write a function called double-radius, which takes in a radius and a color. It produces an outlined circle of whatever color was passed in, with radius twice as big as the input.
If walking through this example as a class, use a projector so kids can see the function being written on the computer.
- Remember how to use the design recipe to work through word problems?
What is the Name of this function? How do you know?
How many inputs does it have in its Domain?
What kind of data is the Domain?
What is the Range of this function?
What does this function do? Write a Purpose Statement describing what the function does in plain English.
Review the purpose of Contracts: once we know the Name, Domain, and Range of a function, it’s easy to write examples using those datatypes.
Using only the Contract and Purpose Statement, see if you can answer the following questions:
Don’t forget to include the lines examples: and end! Your examples should look similar to:
Every example begins with the name of the function. Where could you find the name of the function?
Every example has to include sample inputs. Where could you find out how many inputs this function needs, and what type(s) they are?
Every example has to include an expression for what the function should do when given an input. Where could you look to find out what this function does?
Write two examples on your paper, then circle and label what is changing between them. When labeling, think about what the changing things represent.
Each one of these answers can be found in the Contract or Purpose Statement. Suggestion: Write these steps on the board, and draw arrows between them to highlight the process. The goal here is to get students into the habit of asking themselves these questions each time they write examples, and then using their own work from the previous step to find the answers.
- variables in the function definition.Once you know what is changing between our two examples, you can define the function easily. The things that were circled and labeled in the examples will be replaced with
Underneath your examples, copy everything that doesn’t change, and replace the changing things with the variable names you used. (Don’t forget to add the fun and end keywords, as well as the colon (:) after the function header!)
For more practice, turn to Page 9 in your workbook and complete the Design Recipe for the double-width function.
Check students understanding: Why do we use variables in place of specific values? Why is it important to have descriptive variable names, as opposed to n or x? Remind students about nested functions: A function whose range is a number can be used inside of a function requiring a number in its domain, as in circle(2 * 25, "outline", "red").