Referenced from lesson Defining Table Functions
For the word problems below, assume animalA
and animalB
are defined as the data rows for Felix and Midnight, respectively.
Directions: Define a function called is-cat
, which consumes a Row
of the animals table and computes whether the animal is a cat.
Contract and Purpose Statement |
Every contract has three parts…
# is-cat::(r :: Row)->Boolean
# Consumes an animal, and computes whether the species equals "cat"
Examples |
Write some examples, then circle and label what changes…
examples:
__is-cat (animalA)is ___________________________
________ (_______)is ___________________________
end
Definition |
Write the definition, giving variable names to all your input values…
fun is-cat(r):
__r["species"] == "cat"
end
Directions: Define a function called is-young
, which consumes a Row of the animals table and computes whether it is less than four years old.
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.