Referenced from lesson Method Chaining
For the word problems below, assume you have animalA
and animalB
defined in your code.
Directions: Define a function called is-dog
, which consumes a Row
of the animals table and computes whether the animal is a dog.
Contract and Purpose Statement |
Every contract has three parts…
# is-dog::(r :: Row)->Boolean
# Consumes an animal, and computes whether the species == "dog"
Examples |
Write some examples, then circle and label what changes…
examples:
__is-dog ("animalA")is animalA["species"] == "dog"
__is-dog ("animalB")is ___________________________
end
Definition |
Write the definition, giving variable names to all your input values…
fun is-dog(r):
__r["species"] == "dog"
end
Directions: Define a function called is-female
, which consumes a Row of the animals table and returns true if the animal is female.
Contract and Purpose Statement |
Every contract has three parts…
# _________::____________________->_______
# _____________________________________________________
Examples |
Write some examples, then circle and label what changes…
examples:
___________ (_________)is __________________________
___________ (_________)is __________________________
end
Definition |
Write the definition, giving variable names to all your input values…
fun _________(_):
______________________
end
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). Bootstrap:Data Science by Emmanuel Schanzer, Nancy Pfenning, Emma Youndtsmith, Jennifer Poole, Shriram Krishnamurthi, Joe Politz, Ben Lerner, Flannery Denny, and Dorai Sitaram with help from Eric Allatta and Joy Straub is licensed under a Creative Commons 4.0 Unported License. Based on a work at www.BootstrapWorld.org. Permissions beyond the scope of this license may be available by contacting schanzer@BootstrapWorld.org.