On this page:
1 Built-in abstractions
2 Combining built-in abstractions
8.6.0.14

Lecture 18: Built-in abstractions

This assignment is due on Tuesday, October 18 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 ???.

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.

2 Combining built-in abstractions

Exercise 5. Design a function lengths->3 that takes a list of strings and returns a list of numbers, which are the lengths of those strings longer than 3 characters. Use map and filter, rather than following the function template for processing a list.

Exercise 6. Design a function lengths-without-e that takes a list of strings and returns a list of numbers, which are the lengths of those strings that do not contain the letter "e". Use map and filter, rather than following the function template for processing a list.

Optional: Read Chapters 17–18 of the textbook.