Example: computing the totals of items in a list
;; compute the total of the mpg consumption for all cars int the loa list ;; List-of-Auto -> Number ;; (define (total-mpg loa)... ;; Examples: ;; (= (total-mpg mt-loa) 0) ;; (= (total-mpg loa1) 20) ;; (= (total-mpg loa2) 30) ;; (= (total-mpg loa3) 45) ;; Template: ;; (cond ;; [(empty? loa) ...] ;; [else ... (first loa) ;; ... (auto-model (first loa)) ... ;; ... (auto-tank-size (first loa))... ;; ... (auto-mpg (first loa)) ... ;; ... (total-mpg (rest loa)) ...] ;; Program: (define (total-mpg loa) (cond [(empty? loa) 0] [else (+ (auto-mpg (first loa)) (total-mpg (rest loa)))])) ;; Tests: (= (total-mpg mt-loa) 0) (= (total-mpg loa1) 20) (= (total-mpg loa2) 30) (= (total-mpg loa3) 45)