On this page:
1 Built-in abstractions
8.12

Lecture 18: Built-in abstractions🔗

This assignment is due on Tuesday, March 5 at 11:59pm. Submit it using Handin as assignment lecture18.

1 Built-in abstractions🔗

Exercise 1. Look at Figure 95 of the textbook. Choose any one of the functions and answer the following questions about it:
  • What is the name of the function?

  • How many inputs does the function take? What are their names?

  • How many inputs does the signature take? What are their names?

Put your answer in your submission as a comment in the following format:
; Exercise 1
; The function ??? has ??? inputs, called ??? and ???.
; Its signature has ??? inputs, called ??? and ???.
Each ??? should be just one word.

Exercise 2. Design at least one of the following two functions. Use ListOf and filter, rather than following the function template for processing a list.
  • Design a function filter-without-a that takes a list of strings as input and returns the list of all the given strings that do not contain the letter "a". Hint: What is X? The built-in functions not and string-contains? will help.

  • Design a function filter-x<y that takes a list of Posns as input and returns the list of all the given Posns whose X coordinate is less than their Y coordinate. Hint: What is X? Design a helper function that follows the template for processing a Posn.

Exercise 3. Design at least one of the following two functions. Use ListOf and map, rather than following the function template for processing a list.
  • Design a function add-to-all that adds a given number to every number in a given list. Hint: What is X and what is Y? Use either local or lambda.

  • Remember the function move-invaders from Lecture 14: Built-in structures? It takes and returns a [ListOf Posn]. It increases each Y coordinate by 1. Design it again, still named move-invaders. Hint: What is X and what is Y? Design a helper function that follows the template for processing a Posn.

Exercise 4. Remember the function draw-invaders from Lecture 14: Built-in structures? It takes a [ListOf Posn] and returns an Image. It draws a marker at each given location. Design it again, still named draw-invaders, but use foldr rather than following the function template for processing a list. Use any marker image you like and any background image you like. Hint: What is X and what is Y? Design a helper function that follows the template for processing a Posn.

The code written in the videos above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Optional: Read Chapters 17–18 of the textbook.