Referenced from lesson Table Methods
You have the following functions defined below (read them carefully!):
fun lookup-fixed(animal): animal["fixed"] end fun is-dog(animal): animal["species"] == "dog" end fun is-old(animal): animal["age"] > 10 end fun label(animal): text(animal["name"], 20, "red") end
The table t
below represents four animals from the shelter:
name | sex | age | fixed | species | pounds |
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Below are a list of expressions that use table methods. What table do we get, after evaluating each one? Match each expression (left) to the table we get (right).
|
1 |
A |
Produces a table with Toggle, Fritz, and Nori - but not Sunflower. |
|
|
2 |
B |
Produces a table of all four animals, sorted youngest-to-oldest |
|
|
3 |
C |
Produces a table, with only Toggle. |
|
|
4 |
D |
Produces an identical table with an extra column called "dog", whose values are true, true, true, false |
|
|
5 |
E |
Produces a table containing only Nori and Toggle. |
|
|
6 |
F |
Produces a table with all four animals, sorted from heaviest to lightest. |
|
|
7 |
G |
Won’t run: will produce an error |
|
|
8 |
H |
Produces an identical table with an extra column called "sticker", whose values are images |
These materials were developed partly through support of the National Science Foundation,
(awards 1042210, 1535276, 1648684, and 1738598).
Bootstrap:Integrated Oklahoma by Jen Poole
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.