List Manipulation Practice

For each of the following Lisp expressions, write on paper the answer that the Lisp interpreter would give if you typed in the expression. When variable values are defined using setq, use the new value of the variable in subsequent evaluations. You can use the computer to check your answer after doing each question yourself by hand. Try some variations on these examples.
  1. (setq colors '(red yellow ((orange) grey) ((blue) green)))
  2. (car colors)
  3. (first colors)     first is a synonym for car
  4. (cdr colors)
  5. (rest colors)     rest is a synonym for cdr
  6. (cadr colors)
  7. (second colors)
  8. (caddr colors)
  9. (third colors)
  10. (cdddr colors)
  11. (cdaddr colors)
  12. (car (caaddr colors))
  13. For each color in the structure colors, write Lisp code to extract that color.
  14. (cons 'cat '())
  15. (cons '(cat mouse) '())
  16. (setq animals '(cat mouse))
  17. animals
  18. (cons 'bear animals)
  19. animals
  20. (setq animals (cons 'moose animals))
  21. animals
  22. (car animals)
  23. (cons '(bear lion) animals)
  24. (append animals '(tiger giraffe))
  25. animals
  26. (append animals animals animals)
  27. (setq birds (list 'jay 'grackle 'eagle))
  28. (cadr birds)
  29. (list birds animals)
  30. (append birds animals)
  31. (car (list '(armadillo) birds))
  32. (setq zoo (append animals birds))
  33. (cadr zoo)
  34. (car birds)
  35. (reverse animals)
  36. (car (last birds))
  37. (eql 'a 'a)
  38. (eql '() nil)
  39. (eql '(a) '(a))
  40. (equal '(a) '(a))
  41. (eql 2.0 2.0)
  42. (length zoo)
  43. (+ (length animals) (length birds))
  44. (= (+ (length animals) (length birds)) (length (append animals birds)))
  45. (member 'cat animals)
  46. (member 'dog animals)
  47. (assoc (car animals) '((bear 100) (moose 200) (walrus 300)))

Gordon S. Novak Jr.