; A non-empty-list-of-numbers is one of
; - (cons f empty)
; where f is a number
; - (cons f r)
; where f is a number, and r is a non-empty-list-of-numbers
In this case, the template looks as follows:
(define (func-for-nelon a-nelon)
(cond
[(empty? (rest a-nelon)) ...(first a-nelon)...]
[else ...(first a-nelon)...(func-for-nelon (rest a-nelon))...]))
; A non-empty-list-of-numbers is
; (cons f r)
; where f is a number, and r is a list-of-numbers
Here, the template is different, since it must refer to the
template for a regular (non-empty) list-of-numbers.
In particular, you don't make a recursive call;
you think to yourself "Ah, a-nelon contains a (perhaps-empty) list;
i'd better call a function for such regular ol' lists":
(define (f a-nelon) ...(first a-nelon)...(func-for-lon (rest a-nelon))...)To compute the average, what function(s) of general (perhaps-empty) lists do you want to call, as your helper?