Homework 3 for csc324, Fall 1996

List Manipulation in Scheme

  1. Given the following list:

    (define L '((a b (b c) ((d))) (e (f)) g))

    give a sequence of functions that retrieves

    1. a
    2. (b c)
    3. c
    4. (( d ))
    5. d
    6. g
    7. f
  2. Draw tree representation for the above list.
  3. Redo problems 2 and 3 of homework 2 using Scheme.
  4. Write the following functions in Scheme:

    1. sum which computes the sum of all elements in the list, e.g., (sum '(a (b c) d)) is 3.
    2. Do problem 10.7 on p. 419 of Sethi.
    3. Do problem 10.8 on p. 419 of Sethi.
  5. Note: It is a good idea to test your answers using Scheme interpretor. You can store your functions in a file, say, hw3 and then type (load "hw3") within Scheme.

  6. Prove lemma from class:

    (reverse (append La Lb)) = (append (reverse Lb) (reverse La))