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?