CS 307: 5. List Manipulation

Due: Wednesday, October 3, 2001

No certification sheet is required for this assignment. Write your TA's name and discussion section time on your paper.

Scheme Tutor

Run at least two of the exam1 lessons of the Scheme Tutor. Hand in a copy of your Scheme Tutor runs for grading. Download the Tutor again, since some lessons have been added. Of course, it will be to your advantage to do more than two lessons; these lessons are questions from previous exams.

List Manipulation Practice

Evaluate the following Scheme expressions. For each expression, give the answer that the Scheme interpreter would give if you typed in the expression. When variable values are defined using define or set!, use the new value of the variable in subsequent evaluations.

Hand in handwritten answers for the following questions. You can use the computer to check your answers after doing the quesions yourself by hand. Try some variations on these examples.

  1. (define colors '(red yellow ((orange) grey) ((blue) green)))
  2. (car colors)
  3. (cdr colors)
  4. (cadr colors)
  5. (caddr colors)
  6. (cdddr colors)
  7. (cdaddr colors)
  8. (car (caaddr colors))
  9. For each color in the structure colors, write the Lisp code to extract that color from the list structure.
  10. (cons 'cat '())
  11. (cons '(cat mouse) '())
  12. (define animals '(cat mouse))
  13. animals
  14. (cons 'bear animals)
  15. animals
  16. (set! animals (cons 'moose animals))
  17. animals
  18. (car animals)
  19. (cons '(bear lion) animals)
  20. (append animals '(tiger giraffe))
  21. animals
  22. (append animals animals animals)
  23. (define birds (list 'jay 'grackle 'eagle))
  24. (caddr birds)
  25. (list birds animals)
  26. (append birds animals)
  27. (list '(armadillo) birds)
  28. (car (list '(armadillo) birds))
  29. (define zoo (append animals birds))
  30. (cadr zoo)
  31. (car birds)
  32. (reverse animals)
  33. (car (reverse birds))
  34. (eqv? 'a 'a)
  35. (eqv? '() '())
  36. (eqv? '(a) '(a))
  37. (equal? '(a) '(a))
  38. (eqv? 2.0 2.0)
  39. (length zoo)
  40. (+ (length animals) (length birds))
  41. (= (+ (length animals) (length birds)) (length (append animals birds)))
  42. (member 'cat animals)
  43. (member 'dog animals)
  44. (assoc (car animals) '((bear 100) (moose 200) (walrus 300)))