Referenced from lesson Method Chaining (Spring, 2021)

You have the following functions defined below (read them carefully!):

fun is-female(r): r["sex"] == "female"  end
fun kilograms(r): r["pounds"] / 2.2     end
fun is-heavy(r):  r["kilos"] > 25       end

The table t below represents four animals from the shelter:

name sex age fixed pounds

"Toggle"

"female"

3

true

48

"Fritz"

"male"

4

true

92

"Nori"

"female"

6

true

35.3

"Maple"

"female"

3

true

51.6

Match each Pyret expression (left) to the description of what it does (right). Note: one description might match multiple expressions!

 t.order-by("kilos", true)

1

A

Produces a table containing Toggle, Nori and Maple, with an extra column showing their weight in kilograms

t.filter(is-female)
  .build-column("kilos", kilograms)

2

B

Produces a table containing Maple, Nori and Toggle (in that order)

t.build-column("kilos", kilograms)
  .filter(is-heavy)

3

C

Produces a table containing only Fritz.

t.filter(is-heavy)
  .build-column("kilos", kilograms)

4

D

Won’t run: will produce an error

t.build-column("kilos", kilograms)
  .filter(is-heavy)
  .order-by("sex", true)

5

E

Produces a table containing only Fritz, with two extra columns.

t.build-column("female", is-female)
  .build-column("kilos", kilograms)
  .filter(is-heavy)

6

F

Produces a table containing Maple and Fritz

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge 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.