Pens/pencils for the students, fresh whiteboard markers for teachers
Class poster (List of rules, design recipe, course calendar)
Editing environment (WeScheme or DrRacket with the bootstrap-teachpack installed)
Seating arrangements: ideally clusters of desks/tables
In the last lesson you learned about a new kind of data struct, called an auto.
What is an auto? What things are described in an auto struct?
How do you make an auto?
How do you get the model out of an auto? The value? The color?
Last time all of these were used to make an autobody shop, where you had functions that would increase the auto’s hp, or paint it a new color. This next problem will be even harder, so remember to refer back to the last two functions you wrote in your workbook, in case you need some hints.
Take a few minutes to review structs and autos with your students.
You may have heard of the show "Pimp My Ride", where the hosts get an old, beat-up car and make it WAY cooler. Let’s implement something like this in Racket...
Turn to Page 12 in your workbooks. Write a function called pimp, which takes in an Auto and returns a new Auto which has an extra 100 horsepower, has 30 inch rims, is painted red, and has increased in value by $10,000.
What is the contract for this function?
For the first EXAMPLE, let’s upgrade car3. How will you start the example?
(EXAMPLE (pimp car3) ...)
According to the contract, we know that the Range of the pimp function is an auto. How do you make an auto?
What’s the first part of an auto? The model. Does the model change, according to the function’s purpose statement? How do you get the model out of car3?
How do you get the hp out of car3?
Does the horsepower change when we "pimp" our auto? You’ll need to get the hp out of car3, and add 100 to it.
According to the purpose statement, every auto that gets pimped will have 30 inch rims. Does it matter what the original rim size was?
Likewise, every car will be painted red. Do we need to reference the original color at all?
Finally, how do you get the value out of car3? Will the value increase or decrease after the auto is upgraded?
Putting it all together, the first example should look like:
Write one more example, circle what changes, and then define the pimp function. If you’re stuck, look back at the contract and your first example.
This is an opportunity for students to practice nested expressions. Not only will they use accessor functions to access the fields of the original auto, they will need to modify them according to the problem statement. If they get stuck, have them draw the circle of evaluation for adding 100 to the auto’s horsepower, 10,000 to the auto’s value, etc.