Referenced from lesson Method Chaining (Spring, 2021)
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::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 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.