Lab 11: Built-in abstractions
You may submit this lab to lab11 on Handin (this is optional).
Note: Whenever you write a function in this class, follow the design recipe. You will be graded accordingly. Note that choosing a built-in abstraction takes the place of the template step (Step 4).
1 Instructions and review of built-in abstractions
The goal of this lab is to practice using the built-in abstractions provided by the Intermediate Student language (including foldr).
To that end, you will redefine functions you have already designed using built-in abstractions. You should reuse Steps 1 through 3 of your original solutions.
Whenever you decide to use a particular built-in abstraction to solve a problem, you are strongly encouraged to specialize the signature of the abstraction to your problem as a first step. For example, if you are designing a function with signature
; copied? : [ListOf String] -> [ListOf Boolean]
and you decide to use
; map : [X -> Y] [ListOf X] -> [ListOf Y]
notice that you’re taking X to be String and Y to be Boolean. And so now you know the signature of the helper function you must pass to map: namely,
; helper : String -> Boolean
Indeed, if you are right that map is the appropriate abstraction, finding this helper often suffices to solve the entire problem.
2 map
Exercise 1. (from Lab 10: Abstracting data definitions) Define a function hello-all which takes a list of strings and adds "hello " to the beginning of each string.
3 filter
Exercise 2. (from Problem Set 7: Word frequencies) Design a function frequents that consumes a [ListOf Frequency] and produces a [ListOf Frequency] that contains only the Frequencys from the original list where the number is more than 100.
4 build-list
Exercise 3. (from Problem Set 9: Similarities) Design a function tab-sqr that tabulates sqr between the input n and 0 (inclusive) in a list.
5 ormap
Exercise 4. (from Problem Set 9: Similarities) Design a function has-string=? that checks if some string in a given list of strings is the same as a given string. Hint: define the helper function locally.
6 andmap
Exercise 5. Design a function all-close which takes a list of Posns and checks to see if all of them are within 100 units from the origin.
7 foldr
Exercise 6. (from Problem Set 8: Caesar ciphers) Design a function combine-1strings which takes a list of 1Strings and returns it as a single String. It should return "" if the input is empty.
8 Uncategorized
Exercise 7. Design a function all-non-empty which takes a list of lists of something and checks whether they are all non-empty.
Exercise 8. (from Lab 10: Abstracting data definitions) Define a function list-lengths which takes a list of lists of something and returns a list of the lengths of the lists in the given list.
Exercise 9. (from Lab 9: Invaders) Design a function gen-invaders which takes a NaturalNumber and produces a list of Posns. The given number is how many invaders gen-invaders will create with a random x-coordinate (between 0 and 200) and a fixed y-coordinate of 30.