Exercise 22.5.11 Develop a function multiply-all that takes in a list of numbers and returns the result of multiplying them all together.
For example:
(check-expect (multiply-all (cons 3 (cons 5 (cons 4 empty)))) 60)
Hint: What is the “right answer” for the empty list? It may not be what you think at first!
Solution: The data definition is similar to that for list-of-strings:
; A list-of-numbers is either
; empty or
; a nelon (non-empty list of numbers).
#|
(define (function-on-lon L)
; L a list of numbers
(cond [ (empty? L) ...]
[ (cons? L) (function-on-nelon L)]
))
|#
; A nelon looks like
; (cons number lon )
#|
(define (function-on-nelon L)
; L a cons
; (first L) a number
; (rest L) a lon
; (function-on-lon (rest L)) whatever this returns
...)
|#
Any suggestions?