This weekend, you had an exam and several active prep questions. You've been busy. For this reason, we will be canceling lab.
KIDDING!
But, we'll forego the quiz. Instead, we'll start by looking at the active prep questions, and continuing from there.
Challenge Identification (3m)
What problems in the active prep did you have problems with? Lets start by identifying those as a group. We'll build a histogram.
Warmup (30m)
We'll start with small groups. Take one problem and, with a partner, talk it through. Use the recipe.
1. Discuss the problem. Develop a data definition that handles the data discussed in the problem.
2. Write a contract, identifying the type of data being consumed by the function you are writing and the type of data it will evaluate to.
3. Write a purpose, which will state, in simple language, what the function needs to do.
4. Write a dummy header. This is just enough of the function definition to allow you to write tests. Remember: the dummy function, though it might do nothing, must still obey the contract.
5. Write tests using check-expect. They should all fail.
6. Write the body of the function. Follow the template for arbitrarily large data. That means we write our cond statement so that it follows the data in the data definition. First question: Is the list empty? Otherwise, we deal with the first and the rest. What do we do with the rest? We probably continue processing it.
Now, all your tests should pass.
Be prepared to walk the class through this process.
Round Robin (2hr)
Once you've done this, and you're feeling more confident, we're going to drop into a round-robin game where we swap partners every 10 minutes. I want you to take turns explaining, and being explained to, how to walk through these problems.
Driver: You solve the problem by talking through the recipe.
Navigator: You constantly ask questions from the recipe. Don't give hints unless you absolutely have to. If you run out of questions, ask for help from the TA or the instructor.
The explicit goal is to have you talking out loud about the process over, and over, and over. By being the navigator, you're able to focus on the process; by being the driver, you can focus on the code. You must play both roles to get anything out of this exercise.
Problems
- Develop the function between?, which consumes three numbers and produces true if the last is between the first two, otherwise it returns false. Note this function does not actually traverse a list, but instead accesses members of a list.
- Use between? to develop the function three-between?, which consumes two numbers and a list of three numbers and determines if all three numbers in the list are between the first two. Note this function does not actually traverse a list, but instead accesses members of a list.
- Develop a function that computes the length of a list.
- Develop a function contains-true? that consumes a list of booleans and determines whether one of them is true. Consider whether empty contains a true element.
- Develop a function sum-nums that consumes a list of numbers and computes the sum of all of those numbers.
- Develop a function called char-in? that consumes a character and a list of characters. It should return true if any of the characters in the list match the character provided. For example, we might use it this way:
(char-in? #\a (list #\a #\A #\e #\E) - Write a function called vowel?. It should consume a character and tell us whether or not it is a vowel. Your solution will use char-in?, and the implementation of vowel? will not need recursion—it will be a single function call.
- Develop a function that consumes a string and returns the number of vowels present in that string. Your solution might involve the use of the built-in function string->list.
HINT: Your solution will probably make use of vowel?. - Develop a function that consumes a list of strings and returns an onion. For example, the list
'("red" "yellow")should become a(make-onion "red" (make-onion "yellow" (make-onion-core))). - Develop a function that consumes a list of animals and returns the total weight of all the animals in the list. If you are lacking inspiration, implement structures for an elephant, a wombat, and the emu. (This is similar, in some ways, to your previous lab, where you developed definitions for shapes.) The structure definition for animal becomes:
;; An animal is either
;; - An elephant
;; - A wombat
;; - An emu
As part of your solution, first develop animals->weights that consumes a list of animals, and returns a list of weights. - Develop a function that consumes a list of numbers and returns a list of the squares of each of those numbers.
- Develop a function that consumes a list of strings, and returns a list of the lengths of those strings. (Lookup string-length.)
- Develop a function that consumes a list of arbitrary data, and returns the number of symbols in the list. For example, given the list '(3 false "hello" 'dolly 42), the returned value should be 1.
- Develop a function sum-num-acc that consumes a list of numbers and an accumulator. The accumulator is a variable that accumulates the value of the ongoing computation. How is this different from your solution to problem 4? Which do you think requires more RAM? Why?
