- ;; mht created on Nov 15, 2011
-
-
;; average-price : list-of-numbers -> number
-
(define (average-price a-list-of-nums)
-
(cond
-
[(empty? a-list-of-nums) 0]
-
[else
-
(/ (sum-price a-list-of-nums)
-
(count-price a-list-of-nums))]))
-
-
;; sum-price : list-of-nums -> number
-
(define (sum-price a-list-of-nums)
-
(cond
-
[(empty? a-list-of-nums) 0]
-
[else
-
(+ (first a-list-of-nums)
-
(sum-price (rest a-list-of-nums)))]))
-
-
;; count-price : list-of-nums -> number
-
(define (count-price a-list-of-nums)
-
(cond
-
[(empty? a-list-of-nums) 0]
-
[else
-
(+ (count-price (rest a-list-of-nums))
-
1)]))
-
-
;; test
-
(average-price (cons 2 (cons 3 (cons 1 empty))))
- (average-price (cons 2 empty))