• Create the data definition(s) for the input of list->rgb. [Do not use the Listof data abstraction.]

    Solution

      ;; List-of-colors is one of: [PT 1]
      ;; -- empty
      ;; -- (cons Color List-of-colors)
    
      ;; A Color is one of: [PT 1]
      ;; -- 'red 
      ;; -- 'green 
      ;; -- 'blue 
    

    or, equivalently,

      ;; List-of-colors is one of: [PT 2]
      ;; -- empty
      ;; -- (cons 'red   List-of-colors)
      ;; -- (cons 'green List-of-colors)
      ;; -- (cons 'blue  List-of-colors)
    

  • Formulate a contract and a purpose statement for list->rgb:

    Solution

      ;; list->rgb : List-of-colors -> RGB  [PT 1]
      ;; count how many times 'red, 'green, 'blue occur on l [PT 1]
    

  • Provide two distinct function examples:

    Solution [PT 2]

    Given: Wanted:
    empty (make-rgb 0 0 0)
    (list 'green 'green)
    'blue 'red 'green)
    (make-rgb 1 3 1)