17 POINTS

Problem$^b$ 2.   The main purpose of this exercise is to develop the function list->rgb. It consumes a list of basic color symbols ('red, 'blue, 'green); its result is an rgb structure that represents how many times 'red, 'green, and 'blue, respectively, occur in the given list.

(define-struct rgb (red green blue))
;; A RGB is: 
;; -- (make-rgb NaturalNumber NaturalNumber NaturalNumber)

Answer the following questions:

  1. Name the constructor, predicate, and selectors that the structure definition for rgb introduces.

    Solution

    ;; [PT 2: 1 if they mention fewer and no junk]
    make-rgb
    rgb?
    rgb-red rgb-green rgb-blue 
    

  2. Provide a template for a function that consumes an RGB structure.

    Solution

    ;; [PT 1, for all selector expressions]
    ;; program: RGB -> ???
    (define (program an-rgb)
      ... (rgb-red an-rgb)   
      ... (rgb-green an-rgb)
      ... (rgb-blue an-rgb) ...)