Material to Understand

Exercises

  1. Develop a recursive function called my-count that computes the number of times that an atomic key appears as a top-level element in a list. For example, (my-count '(1 2 (3 1) 1) 1) should return a 2 because the atomic key 1 appears as a top level element twice in the list '(1 2 (3 1) 1).
  2. Once the function above is working, trace it, and run it again to make sure that you understand the recursion. To trace the function, type (trace my-count)
  3. Make function my-count tail-recursive. The tail-recursive version should have an optional parameter.
  4. Once the function above is working, trace it.
  5. Change function my-count so that it counts all occurrences of the key. For example, (my-count '(1 2 (3 1) 1) 1) should now return a 3.
  6. Again, trace the function once it is working and make sure that you understand the recursion. Have John take a look at your function to see if there are any improvements that can be made.
  7. Define user-defined-list to do what the primitive list does. Use a rest parameter.
  8. Define my-nthcdr, a function that uses a keyword parameter with a default value of 1. Do not use nthcdr in the function body!