Problems

  1. 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. 

  2. 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. 

  3. Develop a function that computes the length of a list.

  4. 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. 

  5. Develop a function sum-nums that consumes a list of numbers and computes the sum of all of those numbers.

  6. 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)

  7. 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.

  8. 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?.

  9. 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))).

  10. 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.

  11. Develop a function that consumes a list of numbers and returns a list of the squares of each of those numbers.

  12. Develop a function that consumes a list of strings, and returns a list of the lengths of those strings. (Lookup string-length.)

  13. 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. 

  14. 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?

Creative Commons License This work is licensed under a Creative Commons BY-SA 3.0 License.