A6 — Processing and decomposing lists

Practice processing lists using built-in functions; learn to decompose lists and process them yourself, without built-ins.

Due Oct 7, 2026

Estimated time to complete (just the assignment, excluding the prep materials): 1.5–2 hours.

Prep materials: Week 6: Lists continued.

What to do

Create a file a6.arr and add all your code there. Remember to test that the file runs before submitting; double check the context and names. Submit the file to Assignment 6 Submission on Brightspace.

For this assignment, you will work again with the games table from Assignment 3. Do not compute any answers manually or type out list literals that you could extract from the table.

Part 1: Built-in list functions

For this part, you need to use only the built-in list functions from DCIC Section 5.1, and you may not decompose any lists yourself.

  1. Define the name list-game-titles to be the list of titles of the games in the games. Hint.

  2. Define list-game-short-titles to be the list of titles of the games that have at most 10 characters. Hint.

  3. Define list-game-ratings to be the list of ratings of all games in games.

  4. Define max-game-rating to be the highest rating of a game.

  5. Define list-game-ratings-rounded to be the list of ratings rounded to the nearest integer, and define a check-block named check-list-game-ratings-rounded with at least two distinct test cases. Hint 1. Hint 2.

  6. Define a function count-of (along with a check-block named check-count-of) that takes a list and a value, and returns how many times the value occurs in the list. For example, count-of([list: "a", "b", "a"], "a") is 2. Use the following function signature:

    fun count-of<A>(l :: List<A>, v :: A) -> NumNonNegative:

    Click here for a hint

    You will need to use multiple built-in list functions, and you will need a lambda (anonymous) function to deal with the value comparison.

Part 2: Calculator

Recover the implementation of calc from Assignment 4 and add it to your a6.arr file. (You can also use calc from the solution published on Discord.)

Define a function calc-string (along with a check-block named check-calc-string) that takes a string of the form "number operator number" and returns the result of the calculation. Hint.

  • For example, calc-string("3 - 7") is -4, and calc-string("11 % 2") is 1.

  • If the string is not in the correct format, calc-string should throw an error.

Part 3: Decomposing lists

For this part, do not use any built-in list functions except for link, empty, .first, and .rest.

  1. Define list-linked to be the list of numbers 10, 15, 20 built using only link and empty, and define a check-block named check-list-linked that checks that list-linked is equal to [list: 10, 15, 20]. Hint.

  2. Define third-linked to be the third element of list-linked, using only .first and .rest.

  3. Define rest-linked to be the list of the last two elements of list-linked.

  4. Define function round-all (along with a check-block namedcheck-round-all) that takes a list of numbers and returns a list of the numbers rounded to the nearest integer. For example, round-all([list: 3.2, -4.7, 5.55]) is [list: 3, -5, 6]. Check that the result of calling round-all on list-game-ratings is equal to list-game-ratings-rounded. Hint.

  5. Define a function short-titles (along with a check-block named check-short-titles) that takes a list of strings and returns the strings from the list that have at most 10 characters. Check that the result of calling short-titles on list-game-titles is equal to list-game-short-titles.

Part 4: Too many circles

  • Create a blue solid circle with a radius 5.
  • Create a blue solid circle with a radius 10.
  • Create a blue solid circle with a radius 15.
  • … are you tired yet?
  • The whole task is to create blue solid circles with radii 5, 10, 15, 20, 25, 30, 35, 40, 45, 50. How can we do it without writing out each circle manually?

Grading

Auto-graded for correctness and some aspects of style (in particular, handling of erroneous inputs), with named check-blocks auto-graded for coverage.