use context essentials2021 include shared-gdrive("dcic-2021", "1wyQZj_L0qqV9Ekgr9au6RX2iqt2Ga8Ep") gradebook = table: name, semester, SNC, quiz1, quiz2 row: "Ursa", 3, false, 83, 56 row: "Isaias", 4, true, 92, 79 row: "Jackson", 8, true, 61, 0 row: "Isi", 7, false, 90, 87 row: "Thuy", 5, false, 85, 85 row: "Brigida", 5, false, 0, 0 end # In this schoool, advisors are assigned by semester advisors = table: sem, name row: 1, "Pan" row: 2, "Greene" row: 3, "Greene" row: 6, "Pan" row: 7, "Rodriguez" row: 5, "Rodriguez" row: 8, "Greene" row: 4, "Rodriguez" end #| Write a computation to add a column to the gradebook table that includes everyone's advisor 1. Build a column. For each row... a. Extract the semester from the row b. Find the row in the advisor table that matches the extracted semester c. Extract the advisor name from the row |# fun advisor-from-row(student-row :: Row) -> String: doc: "Produces the advisor for the given student row, using advisors table" # a. Extract the semester from the row student-semester = student-row["semester"] # b. Find the row in the advisor table that matches the extracted semester advisor-row = filter-with( advisors, lam(r): r["sem"] == student-semester end).row-n(0) # c. Extract the advisor name from the row advisor-row["name"] end build-column( gradebook, "advisors", # Steps a-c are in the advisor-from-row helper function lam(r): advisor-from-row(r) end) #--------------------------------------------------# fun advisor-from-semester(semester :: Number) -> String: doc: "Produces the advisor for the given semester, using advisors table" # b. Find the row in the advisor table that matches the extracted semester advisor-row = filter-with( advisors, lam(r): r["sem"] == semester end).row-n(0) # c. Extract the advisor name from the row advisor-row["name"] end build-column( gradebook, "advisors", # a. Extract the semester from the row # Steps b-c are in the advisor-from-semester helper function lam(r): advisor-from-semester(r["semester"]) end) #-----------------------------------------------# fun get-advisor(student-name :: String, gradebook-table :: Table, advisor-table :: Table) -> String: student-row = filter-with( gradebook-table, lam(r): r["name"] == student-name end).row-n(0) student-semester = student-row["semester"] advisor-row = filter-with( advisor-table, lam(r): r["sem"] == student-semester end).row-n(0) advisor-row["name"] end # Write a computation to add a column to the gradebook table that includes everyone's advisor # what's the plan? # Using get-advisor: #| 1. Build a column. For each row... a. Extract the student's name from the row b. Use get-advisor to get the student's advisor |# build-column( gradebook, "advisor", lam(r): get-advisor(r["name"], gradebook, advisors) end)